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
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)