当我尝试重新采样以下时间序列时出现错误。似乎只有'MS'重新采样才会失败。如果我在时间序列中再添加一行,则无任何问题。可以弄清楚这里有什么问题:(
dates=[datetime(2014,6,1),datetime(2014,10,1),datetime(2015,2,1)]
ts=pd.Series([1,1,0],index=dates)
ts
2014-06-01 1
2014-10-01 1
2015-02-01 0
ts.resample('MS')
ValueError: Length mismatch: Expected axis has 3 elements, new values have 9 elements
答案 0 :(得分:0)
如果您提到参数how
:
ts.resample('MS', how='mean')
#2014-06-01 1
#2014-07-01 NaN
#2014-08-01 NaN
#2014-09-01 NaN
#2014-10-01 1
#2014-11-01 NaN
#2014-12-01 NaN
#2015-01-01 NaN
#2015-02-01 0