Ternary operator on pandas dataframe

Unfortunately you can use ternary operator like this

a if x>y else b

on pandas dataframe logic. With that said you can use numpy.where instead:

df['result'] = np.where(df1['col1'] > df1['col2'], 1, 0)

There you go. It’s also much faster.