Appending to an empty DataFrame in Pandas? Appending to an empty DataFrame in Pandas? python python

Appending to an empty DataFrame in Pandas?


That should work:

>>> df = pd.DataFrame()>>> data = pd.DataFrame({"A": range(3)})>>> df.append(data)   A0  01  12  2

But the append doesn't happen in-place, so you'll have to store the output if you want it:

>>> dfEmpty DataFrameColumns: []Index: []>>> df = df.append(data)>>> df   A0  01  12  2


And if you want to add a row, you can use a dictionary:

df = pd.DataFrame()df = df.append({'name': 'Zed', 'age': 9, 'height': 2}, ignore_index=True)

which gives you:

   age  height name0    9       2  Zed


You can concat the data in this way:

InfoDF = pd.DataFrame()tempDF = pd.DataFrame(rows,columns=['id','min_date'])InfoDF = pd.concat([InfoDF,tempDF])


matomo