Reputation: 693
I am a complete coding novice and have been experimenting with Pandas. This is my first post. Thank you in advance for your help!
I would like to remove any rows where cat1 does not match either dog1 or dog2. It does not have to match both, just one or the other.
cat1 dog1 dog2
0 red red blue
1 red green blue
2 blue red blue
3 blue blue green
4 red green blue
I would like the end result to be as follows:
cat1 dog1 dog2
0 red red blue
2 blue red blue
3 blue blue green
How do I do this?
Upvotes: 2
Views: 1279
Reputation: 37930
This is really simple:
df.query('cat1 == dog1 or cat1 == dog2')
Upvotes: 3