I am using a pandas dataframe and I am trying to select rows where the
yearID == 2001
team_IDx == 'OAK'
mergeddf.loc[(mergeddf['yearID'] == 2001 & mergeddf['teamID_x'] == 'OAK')]
TypeError: cannot compare a dtyped [object] array with a scalar of type [bool]
This is due to the operator precedence of the bitwise operators, which have higher precedence than logical operators. You need another layer of parentheses around each condition:
mergeddf.loc[((mergeddf['yearID'] == 2001) & (mergeddf['teamID_x'] == 'OAK'))]