Home > Mobile >  Can't to Drop a column name(2021.0)
Can't to Drop a column name(2021.0)

Time:10-09

Want to drop this col

 df3 = df2.drop(labels="2021.0", axis=1)

Error I get

   KeyError: "['2021.0'] not found in axis"

Also done that

  df3=df2.drop(["2021.0"], axis='columns')

But also get same error

dataset

CodePudding user response:

Try without quotes;

df3 = df2.drop(labels=2021.0, axis=1)

CodePudding user response:

Most likely because the column name is not of type String. If you remove the quotes it should work.

df3 = df2.drop(labels=2021.0, axis=1)

or alternatively just

df3 = df2.drop(2021.0, axis=1)
  • Related