Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

ValueError: Dataframe must have columns "ds" and "y" with the dates and values respectively

Ask Question

I have created my data source with ds and y format and am still receiving error as above...please see below code

    import pandas as pd
    import numpy as np
    import pystan
    from fbprophet import Prophet
    import matplotlib.pyplot as plt
    plt.style.use("fivethirtyeight")
    df = pd.read_csv(r'C:\Users\sussmanbl\Desktop\fb prophet ar historical2.csv')
    df['ds'] = pd.to_datetime(df['ds'])
    print(df.head())
    df.dtypes
    plt.figure(figsize=(12,8))
    plt.plot(df.set_index('ds'))
    plt.legend(['AR'])
    m1 = Prophet(weekly_seasonality=True)
    m1 = Prophet(daily_seasonality=True)
    m1.fit(df)
    future = m1.make_future_dataframe(periods=90)
    future.tail().T
    forecast = m1.predict(future)
    forecast[['ds', 'yhat', 'yhat_lower', 'yhat_upper']].tail()
    fig1 = m1.plot(forecast)
    fig2 = m1.plot_components(forecast)
    runfile('C:/Users/sussmanbl/Desktop/Modelling/FB Prophet AR Historical.py', 
    wdir='C:/Users/sussmanbl/Desktop/Modelling')
    Reloaded modules: stanfit4anon_model_ad32c37d592cdbc572cbc332ac6d2ee2_4431954053790800620
    0 2017-01-03 10
    1 2017-01-04 39
    2 2017-01-05 19
    3 2017-01-06 12
    4 2017-01-09 11

Error:

Traceback (most recent call last):
File "", line 1, in
runfile('C:/Users/sussmanbl/Desktop/Modelling/FB Prophet AR Historical.py', 
wdir='C:/Users/sussmanbl/Desktop/Modelling')
File "C:\Users\sussmanbl.conda\envs\stan_env\lib\site- 
packages\spyder_kernels\customize\spydercustomize.py", line 827, in runfile
execfile(filename, namespace)
File "C:\Users\sussmanbl.conda\envs\stan_env\lib\site- 
packages\spyder_kernels\customize\spydercustomize.py", line 110, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
File "C:/Users/sussmanbl/Desktop/Modelling/FB Prophet AR Historical.py", line 17, in
m1.fit(df)
File "C:\Users\sussmanbl.conda\envs\stan_env\lib\site-packages\fbprophet\forecaster.py", line 
1082, in fit
'Dataframe must have columns "ds" and "y" with the dates and '
ValueError: Dataframe must have columns "ds" and "y" with the dates and values respectively.
    df.dtypes
    Out[46]:
    ds datetime64[ns]
    y int64
    dtype: object

i have formatted the source data to be in ds and y format. the dates are in proper format as are the values. im not sure what the code or the source data is missing that is causing the value error to come up

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.