22

I looked at the unique values in a column of a dataframe - pandas that I have. And there are some names in one of the columns that I do not want to include, how do I remove those rows from the dataframe, without using index value notation, but by saying if row value = "this" then remove

like...

new = df.copy

df['some column'].drop_values('this','that','other')

1 Answer 1

45

See indexing with isin (also, boolean indexing):

mask = df['some column'].isin(['this', 'that', 'other'])
df[~mask]
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks @Behzad! does the [~idx] notation, mean show everything in the dataframe which are not in variable, idx? Is this also another way to do it? df[df.line_race != 0] stackoverflow.com/questions/18172851/…
@yoshiserry see Boolean indexing
@yoshiserry also see indexing with isin

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.