'selection on multiple conditions doesn't work correctly in pandas dataframe

I have a dataframe df which I create by loading a csv file and appending another df to (I know that appending is not done in place, so I assign the result of this operation to df). The dataframe has columns: stimulus (contains strings), syllable (contains numbers 1 or 2), response (contains strings). If I do

df[df['syllable']==1]

or

edf[df['syllable']==2]

It selects the rows correctly. But if I do:

df[(df['stimulus'].str.contains("bearded_guy"))&(df['syllable']==1)]

it selects rows where syllable is equal to 2 instead of 1. enter image description here



Solution 1:[1]

Try this:

df.loc[(df['stimulus'].str.contains("bearded_guy"))&(df['syllable']==1), :]

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Rabinzel