filter dataframe on multiple (logical) conditions
Mon Jan 03 2022 13:37:57 GMT+0000 (Coordinated Universal Time)
Saved by
@ahoeweler
# filter col1 by numbers greater than 8 but smaller than 10
df[np.logical_and(df['col1'] > 8, df['col1'] < 10)]
# other way
dogs[(df['breeds'] == 'Labrador') & (df['color'] == 'brown')]
# other way
dogs[dogs['color'].isin(['brown', 'black'])]
# other way (if applied on index)
dogs.loc[['brown', 'black']]
content_copyCOPY
Comments