Reputation: 1146
I’m not anywhere near a computer right now so I can’t test this out, but can I .loc by a list?
As in, I regularly do
df.loc[df[‘col’] == ‘this’]
Can I do
df.loc[df[[‘col1’, ‘col2’]] == [‘this’, ‘that’]]
Upvotes: 0
Views: 651
Reputation: 323266
Check with tuple
df.loc[df[['col1', 'col2']].apply(tuple,1) == ('this', 'that')]
Upvotes: 0
Reputation: 13242
Yeah, you can do something like:
df.loc[df[['col1', 'col2']].eq(['this', 'that']).all(axis=1)]
Upvotes: 1
Reputation: 54698
No, but you can do:
df.loc[df['col1'] == 'this' & df['col2'] == 'that']
Upvotes: 0