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 append the new data to a list and put the list data in the data frame.

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 call data.append to append the data in the data list.

Then we create the data frame from data using pd.DataFrame with data and set columns to an array with the column names.

Leave a Reply

Your email address will not be published.

If you like the content of this blog, subscribe to my email list to get exclusive articles not available to anyone else.