xxxxxxxxxx
Creating Pandas dataframe using list of lists ; df = pd.DataFrame(data, columns = [ 'Name' , 'Age' ])
xxxxxxxxxx
#import module
import pandas as pd
#have your data as a list of lists - they will each be a ROW
data = [['Stanley', 10, 'blue'],
['Kyle', 9, 'green'],
['Kenny', 10, 'orange'],
['Cartman', 10, 'turquoise']]
#convert to Dataframe specifying columns names
df = pd.DataFrame(data, columns=['Name','Age','Hat Color'])
xxxxxxxxxx
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)
xxxxxxxxxx
# import pandas as pd
import pandas as pd
# list of strings
lst = ['Geeks', 'For', 'Geeks', 'is', 'portal', 'for', 'Geeks']
# list of int
lst2 = [11, 22, 33, 44, 55, 66, 77]
# Calling DataFrame constructor after zipping
# both lists, with columns specified
df = pd.DataFrame(list(zip(lst, lst2)),
columns =['Name', 'val'])
xxxxxxxxxx
>>> df = pd.DataFrame([[1,2,3],[3,4,5]])
>>> lol = df.values.tolist()
>>> lol
[[1L, 2L, 3L], [3L, 4L, 5L]]