I have the following dataframe:
data/hora
2017-08-18 09:22:33 22162 NaN 65.9 NaN NaN
2017-10-03 11:08:26 22162 NaN 60.5 NaN NaN
2018-02-17 01:45:24 22162 NaN 69.7 NaN NaN
2018-02-17 01:45:55 74034 NaN 67.5 NaN NaN
2018-02-17 01:46:29 74034 NaN 65.4 NaN NaN
2018-02-17 01:47:20 74034 NaN 63.3 NaN NaN
2018-02-17 01:48:35 74034 NaN 61.3 NaN NaN
2018-02-17 01:49:08 17448 NaN 63.4 NaN NaN
2018-02-17 01:49:31 17448 NaN 65.5 NaN NaN
2018-02-17 01:49:55 17448 NaN 67.6 NaN NaN
To which I want to fill the NaN as the mean of which column. However, this value change as the 'Machine' changes - there are three machine values.
Therefore, I need I fillna
that changes according to Machine column value.
I tried:
for i in df:
if i.isin(df.loc[df['Machine'] == '22162']):
df.fillna(df.loc[df['Machine'] == '22162'].mean)
elif i.isin(df.loc[df['Machine'] == '17448']):
df.fillna(df.loc[df['Machine'] == '17448'].mean)
elif i.isin(df.loc[df['Machine'] == '74034']):
df.fillna(df.loc[df['Machine'] == '74034'].mean)
But it didn't work.
Thanks!