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