DekGenius.com
PYTHON
from list of lists to dataframe
import pandas as pd
data = [['New York Yankees', 'Acevedo Juan', 900000, 'Pitcher'],
['New York Yankees', 'Anderson Jason', 300000, 'Pitcher'],
['New York Yankees', 'Clemens Roger', 10100000, 'Pitcher'],
['New York Yankees', 'Contreras Jose', 5500000, 'Pitcher']]
df = pd.DataFrame.from_records(data)
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)
List to Dataframe
# import pandas as pd
import pandas as pd
# list of strings
lst = ['fav', 'tutor', 'coding', 'skills']
# Calling DataFrame constructor on list
df = pd.DataFrame(lst)
print(df)
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
how to convert a list to dataframe in python
import pandas as pd
from pandas import DataFrame
df = DataFrame(lst,columns=['num'])
dataframe to list of lists
>>> df = pd.DataFrame([[1,2,3],[3,4,5]])
>>> lol = df.values.tolist()
>>> lol
[[1L, 2L, 3L], [3L, 4L, 5L]]
convert list of lists to pandas dataframe
salary = [['Company', 'Job', 'Salary($)'],
['Google', 'Machine Learning Engineer', 121000],
['Google', 'Data Scientist', 109000],
['Google', 'Tech Lead', 129000],
['Facebook', 'Data Scientist', 103000]]
df = pd.DataFrame(salary[1:], columns=salary[0])
© 2022 Copyright:
DekGenius.com