我正在尝试从每季度到每月对数据框进行下采样。
i = ['2000-01-01','2000-04-01','2000-07-01','2000-10-01','2001-01-01','2001-04-01','2001-07-01','2001-10-01']
d = [0,54957.84767,0,0,0,56285.54879,0,0]
df = pd.DataFrame(index=i, data=d)
df.index = pd.to_datetime(df.index,infer_datetime_format=True)
df.index = df.index.to_period('Q')
df.resample('M').interpolate(method='cubic')
这会引发 TypeError:
TypeError: ufunc 'isnan' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''
如果我跳过这一行:
df.index = df.index.to_period('Q')
然后它只会产生nans