mercredi 25 novembre 2020

I need to calculate the mean between 2 columns with some nan value

good evening,

in a dataframe I need to calculate the mean between 2 columns('wr_max' e 'wr_min'), when I do not have the value (NaN) 'wr_max' i want to set 'wr'= 'wr_min'. I tried to execute this code but the second part overwrites all the lines. in which part am I wrong?

for index in recenti:
    if index in recenti[recenti['wr_max'].notnull()]:
        recenti['wr'] = (recenti['wr_max'] + recenti['wr_min']) / 2
    if index in recenti[recenti['wr_max'].isnull()]:
        recenti['wr'] = recenti['wr_min']
recenti.head()

if i make only this rows, everything works but obviously with some missing data.

   for index in recenti:
        if index in recenti[recenti['wr_max'].notnull()]:
            recenti['wr'] = (recenti['wr_max'] + recenti['wr_min']) / 2

but when i make all code rows the second part works indistinctly on all rows of the dataframe.

Aucun commentaire:

Enregistrer un commentaire