Answers for "how to transform variable list e columns dataframe python"

0

list to dataframe columns

import pandas as pd

lst = [1,2,3]
df = pd.DataFrame([lst])
df.columns =['col1','col2','col3']
df

to get this:

    col1    col2    col3
0   1       2       3
Posted by: Guest on October-21-2021
0

python - convert a list column into miltiple columns

# Method 1
df[['team1','team2']] = pd.DataFrame(df.column_with_list.tolist(), index= df.index)

# Method 2
df['team1'], df['team2'] = list(zip(*((x[0], x[1]) for x in df['column_with_list'].values)))
Posted by: Guest on December-17-2020

Code answers related to "how to transform variable list e columns dataframe python"

Python Answers by Framework

Browse Popular Code Answers by Language