As its documentation says, pandas dataframes are a data structure that contains labeled axes (rows and columns). iloc[]
(and iat[]
) are integer-location based indexers. Enlarging a dataframe means there will have to be a new index label for the enlarged part; however, iloc
(and iat
) being integer indexers wouldn't "understand" that.
loc[]
and at[]
, being label-based indexers are OK.
df.loc[len(df)] = value
# or
df.at[len(df), 'col'] = value
Here the value of len(df)
becomes the new label.
If the job is to add multiple rows to a dataframe, consider using concat()
instead:
df = pd.concat([df, new_df])