【发布时间】:2012-12-30 23:05:41
【问题描述】:
我想使用 pandas OLS 函数将趋势线拟合到我的数据系列。有谁知道如何使用 pandas 系列中的日期时间索引作为 OLS 中的预测器?
例如,假设我有一个简单的时间序列:
>>> ts
2001-12-31 19.828763
2002-12-31 20.112191
2003-12-31 19.509116
2004-12-31 19.913656
2005-12-31 19.701649
2006-12-31 20.022819
2007-12-31 20.103024
2008-12-31 20.132712
2009-12-31 19.850609
2010-12-31 19.290640
2011-12-31 19.936210
2012-12-31 19.664813
Freq: A-DEC
我想使用索引作为预测器对其进行 OLS:
model = pd.ols(y=ts,x=ts.index,intercept=True)
但由于 x 是日期时间索引的列表,该函数返回错误。有人有想法吗?
我可以使用 scipy.stats 中的 linregress,但我想知道 Pandas 是否可以。
谢谢, 格雷格
【问题讨论】:
-
我的 pandas 没有 ols 功能。你能添加如何导入它吗?可能,更新问题。
标签: python datetime pandas linear-regression series