I'm trying to create an empty dataframe and append it regularly.
This is the code I'm using:
import pandas as pd
column_names = ["number", "number2"]
df = pd.DataFrame(columns=column_names)
#df_list = list(df)
#print(df_list)
x = []
for i in range(1,10):
x.append([(i+1), (i+2)])
new = df.append(x)
print(new)
However when I append it. This is the result I get. Obviously, I would like to have the numbers under the column names and not in new columns.
number number2 0 1
0 NaN NaN 2.0 3.0
1 NaN NaN 3.0 4.0
2 NaN NaN 4.0 5.0
3 NaN NaN 5.0 6.0
4 NaN NaN 6.0 7.0
new = df.append(pd.DataFrame(x,columns=column_names))outside the loop , pretty much similar to Quangs method