Hi so currently I am trying to create an empty dataframe in python using this code:
for i in range (len('bus0')):
empty_df = pd.DataFrame(np.nan, index=[i], columns=['bus0', 'bus1'])
print(empty_df)
But I am getting an output (below) which reprints the column headers bus0 and bus1 for each index in the dataframe:
bus0 bus1
0 NaN NaN
bus0 bus1
1 NaN NaN
bus0 bus1
2 NaN NaN
bus0 bus1
3 NaN NaN
I do not want the column headers to keep reappearing for each index, I just want them to show up once at the top. How does one achieve this?
question from:https://stackoverflow.com/questions/65831090/why-am-i-getting-column-headers-for-each-index-of-a-dataframe-in-python