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 "
", line 5, in 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:
I think the exception is pretty clear: Prophet object can only be fit once. Instantiate a new object. You are trying fit in a loop.
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.
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.
@VishnuPrashanthCVI Hi Vishnu ! I'm encountering the same issue. How did you filtered the values that had less the 2 data values ?
Prophet cannot be used when number of rows(that are not null) in your data (that you're passing) is less than 2. So you cannot do the prediction in that case!
So you get an error when you're fitting the model!
There's no other solution other than adding more (not null) data to the existing!
My dataframe doesnot contain nan values but still i am facing this issues can anyone help me how to filter that
My dataframe doesnot contain nan values but still i am facing this issues can anyone help me how to filter that
it's not about about nan values , you should have at least two points on your dataframe to make predictions , so if your are training serveral models into a for loop you can add this condition: if df.shape[0] > 2: m.fit(df)
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.
i am getting same error...can you please help me
I had the same problem and solved it with @VishnuPrashanthCVI's answer
Hi I am facing similar issues, ValueError: Dataframe has less than 2 non-NaN rows. where exectly we would have to change the logic. please help us
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.
Hi Hasshes, Could you please help me, how do we resolve this issues. what kind of fix required. and I have raise similar help as below stackoverflow. kindly assist.
Hi All, I am facing simialr issues and posted in stackoverflow, please some one help us where we have to change or fix the code.
Hi All, I am facing simialr issues and posted in stackoverflow, please some one help us where we have to change or fix the code.
if your are training serveral models into a for loop you can add this condition: if df.shape[0] > 2: m.fit(df)
stiti-bacem
@stiti-bacem @VishnuPrashanthCVI - please help me this issues, how do handle in code.
Hi All, I am stiill expecting your help to fix the NaN issues, kindly suggest