Beatriz
Beatriz

Reputation: 3

How to drop columns other than the ones mentioned?

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.

Upvotes: 0

Views: 32

Answers (1)

Derek O
Derek O

Reputation: 19600

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

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

Upvotes: 1

Related Questions