Here is how to create a pandas DataFrame from a list in Python.


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) 

Output

   Celsius  Fahr  Kelvin

0       10    20      30

1        4     5       6

2        7     8       9


Explanation

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)


Related HowTos
Deploy a web app to Heroku
Schedule a Python script for execution at a specific time every day
Store Python passwords securely on Windows, Mac, and Linux
Do dictionary comprehension
Do list comprehension
Create a virtual environment
Create a new file
Merge two lists
Extract items from two different lists into one list
Check if a text file is empty
Randomly select an item from a list
Generate a random integer
Break a while loop
Create a pandas DataFrame from a dictionary
Get the last item of a list
Delete a column from a pandas dataframe
Access a column of a pandas dataframe
Create a class
Make a webpage request
Get the first two characters of a string
Loop through two lists at the same time
Recommended Course

Learn Flask development and learn to build cool apps with our premium Python course on Udemy.


Mailing List

We will keep you Python-motivated if you subscribe below.