I am struggling with something that might seem simple:
I want to replace NaN
by the mean of the value for the Disease
import numpy as np
import pandas as pd
df = pd.DataFrame({'Disease' : [1, 0, 0, 1, 1], 'Value1' : [3, 1, 2, 4, np.nan],
'Value2' : [13, 21, np.nan, 16, 87], 'Value3' : [np.nan, 5, 11, 54, np.nan]})
I want to replace the NaN
value by these:
df.groupby(by='Disease').mean()
I tried to loop through the dataframe but I am stuck when I try to assign the new value in the original dataframe.
Can someone help me?
Thank you