Home > Software design >  How to drop columns other than the ones mentioned?
How to drop columns other than the ones mentioned?

Time:01-18

I know there is a function .drop() which removes the columns I mention inside the parentheses. I need the opposite: to remove all the columns except the ones I indicate.

I tried: df = df.drop(columns != ['Plant', 'Date', 'Type']) hoping I would get my dataframe only with those columns.

CodePudding user response:

I think it's simpler to directly select the columns you want to keep:

df = df[['Plant', 'Date', 'Type']]
  • Related