-1
Good afternoon. I have a Dataframe with the following head():
Note that in the bmi column there are Nan values, more precisely, there are 201 lines. I want to change this value based on the age column, so I created these rules:
median1 = base.loc[(base['age'] >= 18) & (base['age'] < 30)].mean().age # media entre 18 a 30 anos
median2 = base.loc[(base['age'] >= 30) & (base['age'] <= 45)].mean().age # media entre 30 a 45 anos
median3 = base.loc[(base['age'] >= 46) & (base['age'] <= 65)].mean().age # media entre 46 a 65 anos
median4 = base.loc[(base['age'] >= 66) & (base['age'] <= 83)].mean().age # media entre 30 a 45 anos
How do I change the bmi column by following these conditions? I tried using Oc, using np.select and so on. Ex of the code:
base.Loc[(base['age'] >= 18) & (base['age'] < 30) & (base['bmi'] ==np.Nan), 'bmi'] = median1.age The documentation says I can pass a condition and the new value, but when this kind of more complex condition happens, it just won’t.
That’s what you want?
base.loc[(base['age'] >= 18) & (base['age'] < 30), "bmi"] = base.loc[(base['age'] >= 18) & (base['age'] < 30)].mean().age
– Paulo Marques
This way, changes all that are among the values. I would like to change only those that have missing values.
– vinicius peres