【发布时间】:2022-12-03 00:31:11
【问题描述】:
我想预测一些数据,这里是 csv 表的例子:
| Time Period HR | Fin | Legal | Leadership | Overall |
|---|---|---|---|---|
| 2021Q2 | 42 | 36 | 66 | 53 |
| 2021Q3 | 52 | 43 | 64 | 67 |
| 2021Q4 | 65 | 47 | 71 | 73 |
| 2022Q1 | 68 | 50 | 75 | 74 |
| 2022Q2 | 72 | 57 | 77 | 81 |
| 2022Q3 | 79 | 62 | 75 | 78 |
我想对每个季度做出预测,直到 2023 年第四季度末。
我发现一篇文章做类似的事情但没有多个值列(Y 轴)
我尝试修改我的代码以允许这样做,但出现错误。
这是我的代码(我更改了内容以简化我的表格,最初有 12 列而不是 5 列):
import pandas as pd
from datetime import date, timedelta
import datetime
import matplotlib.pyplot as plt
plt.style.use('fivethirtyeight')
from statsmodels.tsa.seasonal import seasonal_decompose
from statsmodels.graphics.tsaplots import plot_pacf
from statsmodels.tsa.arima_model import ARIMA
import statsmodels.api as sm
import warnings
import plotly.graph_objects as go
# import make_subplots function from plotly.subplots
# to make grid of plots
from plotly.subplots import make_subplots
'set filepath'
inputfilepath = 'C:/Documents/' \
'Forecast/Input/' \
'Forecast Data csv.csv'
df = pd.read_csv(inputfilepath)
print(df)
import plotly.express as px
figure = px.line(df, x="Time Period",
y=("Fin","Legal","Leadership","Overall"),
title='Quarterly scores')
figure.show()
但是,我遇到了以下错误:
ValueError:所有参数都应具有相同的长度。的长度 argument
y是 4,而先前处理的长度 arguments ['Time Period'] 是 6我将如何更改我的代码以生成包含多个 y 变量(Fin、Legal、Leadership、Overall)的图表?
此外,这是我找到的文章的链接:
https://thecleverprogrammer.com/2022/09/05/business-forecasting-using-python/
【问题讨论】:
标签: python pandas matplotlib