How Can I Remove Multiple Rows With Different Labels In One Command In Pandas?
I have a pandas dataframe that looks like the one below, and I want to drop several labels. What works fine is: df = df[df['label'] != 'A'] or: df = df[(df['label'] != 'A') &
Solution 1:
try this:
import numpy as np
df = df[np.logical_not(df['label'].isin(['A','B']))]
or
df = df[- df['label'].isin(['A', 'B'])]
see Remove rows not .isin('X')
Post a Comment for "How Can I Remove Multiple Rows With Different Labels In One Command In Pandas?"