gaut
gaut

Reputation: 5958

Python Pandas multiple filtering conditions

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

Answers (1)

Tom Ron
Tom Ron

Reputation: 6181

Try. adding brackets -

df2[(df2['id'].isin(df1['id'])) & (df2['type']=='image')]    

Upvotes: 1

Related Questions