Home > Mobile >  Conditional column calculation in pandas
Conditional column calculation in pandas

Time:10-08

I want to apply below calculations to only rows that meet certain criteria.

i.e where snapshot column = '2021-02-02'

df['numerator']/df['denominator']

how do I do that?

CodePudding user response:

IIUC use:

m = df['snapshot'] == '2021-02-02'

df.loc[m, 'new'] = df['numerator']/df['denominator']
  • Related