0

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')
Sociopath
  • 13,068
  • 19
  • 47
  • 75
Garima
  • 1
  • 1
  • Welcome to StackOverflow. Please take the time to read this post on [how to provide a great pandas example](http://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) as well as how to provide a [minimal, complete, and verifiable example](http://stackoverflow.com/help/mcve) and revise your question accordingly. These tips on [how to ask a good question](http://stackoverflow.com/help/how-to-ask) may also be useful. – jezrael Feb 26 '18 at 06:23
  • Can you also explain what is wrong? – jezrael Feb 26 '18 at 06:23
  • Please post a sample dataframe and your expected result – Pyd Feb 26 '18 at 06:39

0 Answers0