Modify the formula below so that it rounds to the nearest integer, but not less than 1 and not more than 4: df2['respiratory_rate'] = df2['respiratory_rate'].fillna( df2.groupby('pulse')['respiratory_rate'].transform('median'))
def rounder(x): if x < 1: return 1 if x > 4: return 4 else: return round(x) df2['respiratory_rate'] = df2['respiratory_rate'].apply(rounder)