Convert Pandas Dataframe To List Code Example


Example 1: python - convert a column in a dataframe into a list


myvar_list = df["myvar"].tolist()

Example 2: how to convert a list into a dataframe in python


from pandas import DataFrame

People_List = ['Jon','Mark','Maria','Jill','Jack']

df = DataFrame (People_List,columns=['First_Name'])
print (df)

Example 3: pandas to list


df.values.tolist()

Example 4: pandas list to df


# import pandas as pd 
import pandas as pd

# list of strings
lst = ['Geeks', 'For', 'Geeks', 'is',
'portal', 'for', 'Geeks']

# Calling DataFrame constructor on list
df = pd.DataFrame(lst)
df

Example 5: convert list to dataframe


L = ['Thanks You', 'Its fine no problem', 'Are you sure']

#create new df
df = pd.DataFrame({'col':L})
print (df)

col
0 Thanks You
1 Its fine no problem
2 Are you sure

Example 6: how to convert a list to dataframe in python


import pandas as pd
from pandas import DataFrame
df = DataFrame(lst,columns=['num'])

Comments

Popular posts from this blog

Converting A String To Int In Groovy

"Cannot Create Cache Directory /home//.composer/cache/repo/https---packagist.org/, Or Directory Is Not Writable. Proceeding Without Cache"

Android How Can I Convert A String To A Editable