import pandas # Create a sample list of lists mylist = [[10, 20, 30], [4, 5, 6], [7,8,9]] # Prepare columns names, one for each sublist mycolumns = ['Celsius', 'Fahr', 'Kelvin']
# Create dataframe from the list of lists df = pandas.DataFrame(mylist, columns=mycolumns)
# Print out the dataframe print(df)
Celsius Fahr Kelvin
0 10 20 30
1 4 5 6
2 7 8 9
The above example constructs a dataframe from a list of lists. If you just want to create a dataframe from a plain list, the code would be as below:
mylist = [10, 20, 30]
mycolumns = ['Celsius']
df = pandas.DataFrame(mylist, columns=mycolumns)
Learn Flask development and learn to build cool apps with our premium Python course on Udemy.
Subscribe to be the first to know when a new Python course is released.