prophet: ValueError: Dataframe has less than 2 non-NaN rows.

I am new to using prophet and trying to run the model in a “for loop”. After few iterations I get a “ValueError: Dataframe has less than 2 non-NaN rows.”

Below is my code:

`prediction = {} df2 = df2.rename(columns={‘Date of the document’: ‘ds’,‘Quantity sold’: ‘y’, ‘Article bar code’: ‘article’}) list_articles = df2.article.unique()

for article in list_articles: article_df = df2.loc[df2[‘article’] == article] my_model = Prophet(weekly_seasonality= True, daily_seasonality=True,yearly_seasonality=True) my_model.fit(article_df) future_dates = my_model.make_future_dataframe(periods=12, freq=‘MS’) forecast = my_model.predict(future_dates) prediction[article] = forecast return prediction`

Below is the error that appears:

File “<ipython-input-101-a0f1073a32cb>”, line 5, in <module> my_model.fit(article_df)

File "C:\Anaconda\lib\site-packages\fbprophet\forecaster.py", line 775, in fit
raise ValueError('Dataframe has less than 2 non-NaN rows.')

ValueError: Dataframe has less than 2 non-NaN rows.

Attaching the screenshot of the error function:

ef

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 15

Most upvoted comments

Hi, I just realize that my comment was not relevant in any way. That wasn’t even the error. But its good that you have fixed it.

My dataframe doesnot contain nan values but still i am facing this issues can anyone help me how to filter that

Hi Hassheh,

Thanks for your response. I found the cause of the issue and resolved it. The model needs to have at least 2 values to do prediction. So, I filtered out the values that had less the 2 data values and then ran the model and got the results successfully.

will close the issue.