how to reset index pandas dataframe after dropna() pandas dataframe
I"m not sure how to reset index after dropna()
df_all = df_all.dropna()
df_all.reset_index(drop=True)
but after drop row index would skip for example jump from 0,1,2,4 ..
Solution 1:
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
.