I have test the code to add multiple empty row to Pandas DataFrame it worked.
import pandas as pd
df = pd.DataFrame({'name': ["James", "White", "John"],
'rebounds': [7, 7, 8]})
for i in range(100):
dft = df.columns.values.tolist()
s = pd.Series(dft)
df.loc[len(df)] =s
print(len(df.index))
In my application I have this code, its adding 16 empty rows but it adds only 4 rows.
print(f"Before adding {len(df3.index)}")
dft = df3.columns.values.tolist()
s = pd.Series(dft)
for i in range(16):
df3.loc[len(df3)] =s
print(f"After adding {len(df3.index)}")
Output
Before adding 221
After adding 225
why its not adding 16 empty rows in my application code? How to troubleshoot this issue?
Thanks
iin thefor i in range()is to instead dofor _ in range(16). This can make it clearer to anyone reading the code that you are never going to use / never going to call thei(which we have changed to_). it won't have any change on how the code runs, just one how someone reads it