Reputation: 3
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
Reputation: 19600
I think it's simpler to directly select the columns you want to keep:
df = df[['Plant', 'Date', 'Type']]
Upvotes: 1