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')
drop() method you can drop/remove/delete rows from DataFrame. axis param is used to specify what axis you would like to remove. By default axis = 0 meaning to remove rows. Use axis=1 or columns param to remove columns.
Use pandas. DataFrame. drop() method to delete/remove rows with condition(s).
See indexing with isin
(also, boolean indexing):
mask = df['some column'].isin(['this', 'that', 'other'])
df[~mask]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With