I've got this silly problem that I just can't seem to get my head around. I'm trying to resample a pandas dataframe using medians, but it just spits out errors like:
ValueError: Wrong number of items passed 81, placement implies 80
or
ValueError: Shape of passed values is (1, 3), indices imply (1, 2)
I'm not able (yet) to to reproduce the first error -- when I try to I get the second error so they seem to be "related enough". The following snippet will reproduce the second error:
data = {'state': ['Ohio', 'Ohio', 'Ohio', 'Nevada', 'Nevada'],
'datetime': [pd.datetime(2008, 10, 30, 0, 0), np.nan, pd.datetime(2008, 11, 2, 0, 0), pd.datetime(2008, 10, 30, 0, 0), pd.datetime(2008, 10, 30, 0, 0)],
'pop': [1.5, 1.7, 3.6, 2.4, 2.9]}
frame = pd.DataFrame(data)
frame.set_index('datetime',inplace=True)
frame.resample('M',how='mean')
frame.resample('M',how='median')
Note that the first resample works - the mean - but the median doesn't. Any ideas about as to why, and how I would work around it to actually get medians would be great (if it's a problem with "median not defined for even number of values" I suppose the average of the two values in the middle would do for me).
Thanks!