Home > Enterprise >  Key Error when trying to drop rows in pandas dataframe based on filter
Key Error when trying to drop rows in pandas dataframe based on filter

Time:11-29

I am unable to drop dataframe rows due to key error. I am trying:

df.drop(df['Year_Map'] == 2021], axis=0, inplace=True)

Error: raise KeyError(f"{labels[mask]} not found in axis"

What is the proper way to drop rows with a filter?

CodePudding user response:

df.drop(df[df.Year_Map == '2021'].index, inplace=True)
  • Related