python - Resample by Date in Pandas — messes up a date in index -
i have multi-index dataframe in pandas, data indexed building, , date. different columns represent different kinds of energy, , values represent how energy used given month. image of dataframe's head here. i'd turn yearly data. have line
df.unstack(level=0).resample('bas-jul').sum()
and works almost perfectly. here issue: dates given 1st of month, reason, resample
, picks july 2nd cut-off 2012. number july 1, 2012 ends being counted in 2011 data. it ends looking this. can see second value in usage month column july 2. other that, resample
appears work perfectly.
if run df.index.get_level_values(1)[:20]
, output is:
datetimeindex(['2011-07-01', '2011-08-01', '2011-09-01', '2011-10-01', '2011-11-01', '2011-12-01', '2012-01-01', '2012-02-01', '2012-03-01', '2012-04-01', '2012-05-01', '2012-06-01', '2012-07-01', '2012-08-01', '2012-09-01', '2012-10-01', '2012-11-01', '2012-12-01', '2013-01-01', '2013-02-01'], dtype='datetime64[ns]', name='usage month', freq=none)
so index july 1 2012 in original dataframe.
any ideas on how fix mini-bug appreciated!
use 'as-jul':
df.unstack(level=0).resample('as-jul').sum()
the b business annual start.
Comments
Post a Comment