Suppose that I have a data frame with 3 columns A, B, C. I would like select the rows for which column B satisfies some condition or column C satisfies some condition. Is there an efficient way of doing this?
To be concrete, suppose I have:
import pandas as pd
df = pd.DataFrame({'A':['mary','john','ashley'],\
'B':['xiao','derric','john'],\
'C':['faye','linnett','bruce']})
I would like to select the rows where column B is John or column C is john. Is there a more elegant to do this than:
df[(df['B']=='John') | (df['C']=='John')]
In my real application, df will have many rows and this row selection is done many times. So efficiency is desirable.