pandas if condition is true code example Example: if condition dataframe python df.loc[df['age1'] - df['age2'] > 0, 'diff'] = df['age1'] - df['age2']