首页 > 解决方案 > Python:将时间序列应用于数据框的每一列并返回一个新行

问题描述

DATE COL1 COL2
28/10/18 10 10
29/10/18 10 10
30/10/18 10 10

我有上述格式的数据。我想使用 python 中的 ARIMA 模型预测日期 31/10/2018 的 COL1 和 COL2 的值。

有没有一种方法可以应用模型在整个数据帧上运行并将结果作为一行

DATE COL1 COL2
31/10/18 10 10

然后在末尾附加值。或者唯一可能的方法是在列中迭代并运行时间序列模型

DATE COL1 COL2
28/10/18 10 10
29/10/18 10 10
30/10/18 10 10
31/10/18 10 10

标签: pythonpandastime-seriesmultiple-columnsapply

解决方案


可能的解决方案:

创建一个使用 ARIMA 模型并仅返回所需数据的函数。

有两种方法:

#applies to the entire data frame (0 = index and 1 = columns)
df2 = df.apply(function, axis=1)

#applies only to the series
df2 = df['date'].apply(function)

有了结果,您已经可以组织数据了解更多https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.apply.html


推荐阅读