Reputation: 5958
Why does the first method with &
give me an empty dataframe, while the second with *
gives me the correct one-line dataframe?
id = ["a","b","c"]
product = ["c","b","d"]
id2 = ["a", "b","z"]
type =["sdca","image","wda"]
df2[df2['id'].isin(df1['id']) * df2['type']=='image']
Out[52]:
id type
1 b image
df2[df2['id'].isin(df1['id']) & df2['type']=='image']
Out[53]:
Empty DataFrame
Columns: [id, type]
Index: []
Upvotes: 0
Views: 22
Reputation: 6181
Try. adding brackets -
df2[(df2['id'].isin(df1['id'])) & (df2['type']=='image')]
Upvotes: 1