zizamuft
zizamuft

Reputation: 93

how do i solve ValueError when running Prophet(), ds and y

I'm trying to learn forecast from

https://facebook.github.io/prophet/docs/quick_start.html#python-api

then let say, I use this df

df = pd.read_csv("https://datahub.io/core/natural-gas/r/daily.csv").iloc[-1000:]
df

after that, I run this code

m = Prophet()
m.fit(df)

it shows error ValueError: Dataframe must have columns "ds" and "y" with the dates and values respectively. I believe that this df already in a proper ds as datestamp and y as numerical

then, I'm trying to run something from another option to lowercase the CSV file but it won't change

Upvotes: 0

Views: 1811

Answers (2)

mohsin-riad
mohsin-riad

Reputation: 36

Your Source dataset column names are not compatible with the Prophet(), So you've to change the names and format it correctly to fit the dataframe into Prophet.

df = pd.read_csv("https://datahub.io/core/natural-gas/r/daily.csv").iloc[-1000:]

new_df=df[['Date','Price']]
new_df['Date']=pd.to_datetime(new_df['Date'])
new_df.rename(columns = {'Date':'ds'}, inplace = True)
new_df.rename(columns = {'Price':'y'}, inplace = True)

m = Prophet()
m.fit(new_df)

Upvotes: 1

Yash J
Yash J

Reputation: 321

What I think is that column name might be an issue here, because the columns of this csv file are Date & Price

Because as it's mentioned in the docs of the API

The input to Prophet is always a dataframe with two columns: ds and y.

And they never said that, we can name it as we want.

So maybe try renaming it and then use it with the API

Let me know if it works or not, if it didn't then we'll search for another solution

Thank you

Upvotes: 0

Related Questions