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:
import pandas
mylist = [10, 20, 30]
mycolumns = ['Celsius']
df = pandas.DataFrame(mylist, columns=mycolumns)
print(df)
Python Mega Course: Learn Python in 60 Days, Build 20 Apps
Learn Python on Udemy completely in 60 days or less by building 20 real-world applications from web development to data science.