Home > OS >  how can i solve the the pandas error for dropping columns
how can i solve the the pandas error for dropping columns

Time:09-26

df.drop(columns=['area_type', 'availability', 'society', 'balcony'], inplace=True)

KeyError: "['area_type' 'availability' 'society' 'balcony'] not found in axis"*

CodePudding user response:

Your dataframe doesn't have these columns, so you can't delete them

CodePudding user response:

Try this:

# axis = 0 for rows
df.drop('column_name', axis=0, inplace=True)

# axis = 1 for columns
df.drop('column_name', axis=1, inplace=True)

Also please check whether the column(s) you are trying to drop are present in your dataframe.

  • Related