prophet icon indicating copy to clipboard operation
prophet copied to clipboard

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

Open VishnuPrashanthCVI opened this issue 8 years ago • 15 comments

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:

ef

VishnuPrashanthCVI avatar Mar 13 '18 08:03 VishnuPrashanthCVI

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.

hassheh avatar Mar 21 '18 11:03 hassheh

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.

VishnuPrashanthCVI avatar Mar 21 '18 13:03 VishnuPrashanthCVI

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.

hassheh avatar Mar 21 '18 13:03 hassheh

@VishnuPrashanthCVI Hi Vishnu ! I'm encountering the same issue. How did you filtered the values that had less the 2 data values ?

antoinecomp avatar Jan 17 '19 16:01 antoinecomp

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!

Ganeshjadhav221b avatar Mar 25 '19 20:03 Ganeshjadhav221b

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

sudhar09 avatar Jun 08 '20 11:06 sudhar09

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)

stiti-bacem avatar Aug 01 '21 17:08 stiti-bacem

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

yj90 avatar Oct 13 '21 06:10 yj90

I had the same problem and solved it with @VishnuPrashanthCVI's answer

tulbureandreit avatar Jul 01 '22 05:07 tulbureandreit

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

elavankarthik84 avatar Dec 02 '22 04:12 elavankarthik84

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.

elavankarthik84 avatar Dec 02 '22 12:12 elavankarthik84

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.

elavankarthik84 avatar Dec 06 '22 07:12 elavankarthik84

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 avatar Dec 06 '22 08:12 stiti-bacem

stiti-bacem

@stiti-bacem @VishnuPrashanthCVI - please help me this issues, how do handle in code.

elavankarthik84 avatar Dec 06 '22 14:12 elavankarthik84

Hi All, I am stiill expecting your help to fix the NaN issues, kindly suggest

elavankarthik84 avatar Mar 30 '23 10:03 elavankarthik84