Categories
Python Answers

How to create an empty Python Pandas DataFrame, then filling it?

Spread the love

To create an empty Python Pandas DataFrame, then filling it, we can create a new data frame with the new items in it.

For instance, we write

data = []
for a, b, c in some_function_that_yields_data():
    data.append([a, b, c])

df = pd.DataFrame(data, columns=['A', 'B', 'C'])

to put all the data in the data list.

Then we use the DataFrame class to create the df data frame from the data and set the columns argument to a list of columns.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *