I need to fill the missing temperature value with the mean value of that month using Imputer() in scikit-learn.
First I split the dataframe into groups based on the month. Then I called the imputer function to calculate the mean for that group and fill in the missing values.
Here is the code I wrote but it didn't work:
def impute_missing (data_1_group): imp = Imputer(missing_values='NaN', strategy='mean', axis=0) imp.fit(data_1_group) data_1_group=imp.transform(data_1_group['datetime']) return(data_1_group) for data_1_group in data_1.groupby(pd.TimeGrouper("M")): impute_missing(data_1_group) Any suggestion?