Converting Lists within Pandas Dataframe into New DataFrame

teteh May

I have a dataframe:

df =

   col1                col2
0  [0.1,0.2,0.3]       [1,2,3]
1  [0.5,0.6,0.7]       [11,12,13]

My goal: to re-create data frame from index 0:

new_df = 
   new_col1    new_col2
0   0.1          1
1   0.2          2
2   0.3          3

What I tried was trying to access row by row:

new_col1 = df.col1[0]
new_col2 = df.col2[0]

But new_col1 results in below instead of a list. So I am unsure how to approach this.

0    [0.1,0.2,0.3]
Name: col1, dtype: object

Thanks.

rhug123

Here is a way by using apply.

df.apply(pd.Series.explode).loc[0]

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

python pandas converting dataframe(s) to lists

From Dev

python pandas converting dataframe(s) to lists

From Dev

Converting tuples in a row to a new columns in pandas Dataframe

From Dev

Converting some columns from pandas dataframe to list of lists

From Dev

converting unstacked dataframe into a dataframe in pandas

From Dev

Converting a dictionary with lists for values into a dataframe

From Dev

Converting specific parts of lists to a dataframe

From Dev

Converting pandas dataframe to CoNLL

From Dev

Converting a List to pandas dataframe

From Dev

Converting pandas dataframe to an array

From Dev

Converting a naive datetime column to a new timezone Pandas Dataframe

From Dev

Converting a naive datetime column to a new timezone Pandas Dataframe

From Java

Pandas DataFrame to List of Lists

From Dev

Pandas dataframe to dictionary of lists

From Dev

Plotting lists in a Pandas dataframe

From Dev

Adding a new row to a MultiIndex pandas DataFrame with both values and lists

From Dev

TypeError converting Pandas dataframe to Spark dataframe

From Dev

Requirements for converting Spark dataframe to Pandas/R dataframe

From Dev

Converting Pandas dataframe into Spark dataframe error

From Dev

converting columns to rows in a Pandas DataFrame

From Dev

converting an HTML table in Pandas Dataframe

From Dev

Converting a list of dicts to a Pandas dataframe

From Dev

Converting time zone pandas dataframe

From Dev

Converting Pandas DataFrame to Orange Table

From Dev

Converting a list of objects to a pandas dataframe

From Dev

Converting a geopandas geodataframe into a pandas dataframe

From Dev

Converting and reshaping a list into a DataFrame in Pandas

From Dev

Converting a pandas dataframe into python dictionary

From Dev

Converting Pandas DataFrame to tkinter object

Related Related

  1. 1

    python pandas converting dataframe(s) to lists

  2. 2

    python pandas converting dataframe(s) to lists

  3. 3

    Converting tuples in a row to a new columns in pandas Dataframe

  4. 4

    Converting some columns from pandas dataframe to list of lists

  5. 5

    converting unstacked dataframe into a dataframe in pandas

  6. 6

    Converting a dictionary with lists for values into a dataframe

  7. 7

    Converting specific parts of lists to a dataframe

  8. 8

    Converting pandas dataframe to CoNLL

  9. 9

    Converting a List to pandas dataframe

  10. 10

    Converting pandas dataframe to an array

  11. 11

    Converting a naive datetime column to a new timezone Pandas Dataframe

  12. 12

    Converting a naive datetime column to a new timezone Pandas Dataframe

  13. 13

    Pandas DataFrame to List of Lists

  14. 14

    Pandas dataframe to dictionary of lists

  15. 15

    Plotting lists in a Pandas dataframe

  16. 16

    Adding a new row to a MultiIndex pandas DataFrame with both values and lists

  17. 17

    TypeError converting Pandas dataframe to Spark dataframe

  18. 18

    Requirements for converting Spark dataframe to Pandas/R dataframe

  19. 19

    Converting Pandas dataframe into Spark dataframe error

  20. 20

    converting columns to rows in a Pandas DataFrame

  21. 21

    converting an HTML table in Pandas Dataframe

  22. 22

    Converting a list of dicts to a Pandas dataframe

  23. 23

    Converting time zone pandas dataframe

  24. 24

    Converting Pandas DataFrame to Orange Table

  25. 25

    Converting a list of objects to a pandas dataframe

  26. 26

    Converting a geopandas geodataframe into a pandas dataframe

  27. 27

    Converting and reshaping a list into a DataFrame in Pandas

  28. 28

    Converting a pandas dataframe into python dictionary

  29. 29

    Converting Pandas DataFrame to tkinter object

HotTag

Archive