I want to fill in missing values in my dataframe data
with the mean calculated per month per year in pandas."Date" is the datetime
column in the format- YYYY-MM-DD
.I am using the following code but the mean values are incorrect:
import pandas as pd
import numpy as np
data["datey"] = data.Date.dt.year
data["datem"]= data.Date.dt.month
data.groupby(['datem','datey']).btc_total_bitcoins.transform(lambda x:
x.fillna(x.mean()))
data.to_csv('test_1.csv')