how to reset index pandas dataframe after dropna() pandas dataframe

The code you’ve posted already does what you want, but does not do it “in place.” Try adding inplace=True to reset_index() or else reassigning the result to df_all. Note that you can also use inplace=True with dropna(), so:

df_all.dropna(inplace=True)
df_all.reset_index(drop=True, inplace=True)

Does it all in place. Or,

df_all = df_all.dropna()
df_all = df_all.reset_index(drop=True)

to reassign df_all.

Leave a Comment