I want to forecast some data, here is an example of the csv table:
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 |
I want to make predictions for every quarter until the end of Q4 2023.
I found an article which does something similar but doesn't have multiple value columns (Y axis)
I tried tailoring my code to allow for this but I get an error.
Here is my code(I've altered the contents to simplify my table, there were originally 12 columns not 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()
However, I am met with the following error:
ValueError: All arguments should have the same length. The length of argument
y
is 4, whereas the length of previously-processed arguments ['Time Period'] is 6
How would I alter my code to produce a graph that contains multiple y variables (Fin, Legal, Leadership, Overall)?
Additionally, this is the link to the article I found:
https://thecleverprogrammer.com/2022/09/05/business-forecasting-using-python/
CodePudding user response:
Looks like your "y" argument accepts only list [ele1, ele2], not a tuple(ele1, ele2). I changed the brackets to squares and I ran your code just fine:
import plotly.express as px
figure = px.line(df, x="Time Period",
y=["Fin","Legal","Leadership","Overall"],
title='Quarterly scores')
figure.show()
produces: this