import pandas as pd
df = pd.DataFrame({'A':[15,14,90,65,20,45],'B':[98,87,45,25,12,5]}) df['C'] = (df['A']>df['B']) and (df['A']+10>df['B']) print(df)
I want the values of column C to be [False, False, True, True, False, True]
Comment From: azjps
Not a pandas dev, but the issue tracker is for reporting issues, not for help questions -- something like stackoverflow is more appropriate. Anyway, use the &
operator: df['C'] = (df['A'] > df['B']) & (df['A']+10>df['B'])
. See for example https://stackoverflow.com/questions/21415661/logic-operator-for-boolean-indexing-in-pandas
Comment From: jreback
docs are pretty good on this: http://pandas.pydata.org/pandas-docs/stable/indexing.html#boolean-indexing