Is it possible to append to an empty data frame that doesn't contain any indices or columns?
I have tried to do this, but keep getting an empty dataframe at the end.
e.g.
import pandas as pd
df = pd.DataFrame()
data = ['some kind of data here' --> I have checked the type already, and it is a dataframe]
df.append(data)
The result looks like this:
Empty DataFrame
Columns: []
Index: []
newDF = pd.DataFrame() #creates a new dataframe that's empty newDF = newDF.append(oldDF, ignore_index = True) # ignoring index is optional
print(df.append(data))
, becauseappend()
always returns None in Pythonappend
was silently removed from the API to discourage people from iteratively growing DataFrames inside a loop :Dappend
inside a loop is quadratic memory usage, so the suggested approach is to accumulate individual rows or DataFrames inside a python list and then convert it into one big df at the end. More information in my answer