Pandas: Check if row exists with certain values
Turns out it is really easy, the following does the job here:
>>> ((df['A'] == 2) & (df['B'] == 3)).any()True>>> ((df['A'] == 1) & (df['B'] == 2)).any()False
Maybe somebody comes up with a better solution which allows directly passing in the array and the list of columns to match.
Note that the parenthesis around df['A'] == 2
are not optional since the &
operator binds just as strong as the ==
operator.