Sep-19-2019, 09:10 AM
Hello,
I have an error ocurred in a code in Python- Jupyter. I am new in python. The error ocurred where it's used pd.rolling_std. I don't know why it doesn't work beacuse I used this code before and it worked perfect. Anyone knows what happen? I saw the answer to the same question but it doesn't work for me.
Thank you
Here is the code:
I have an error ocurred in a code in Python- Jupyter. I am new in python. The error ocurred where it's used pd.rolling_std. I don't know why it doesn't work beacuse I used this code before and it worked perfect. Anyone knows what happen? I saw the answer to the same question but it doesn't work for me.
Thank you
Here is the code:
import pandas as pd import numpy as np def score(SeriesTemps, window): # normalization SeriesTempsNorm=(SeriesTemps-SeriesTemps.mean())/(SeriesTemps[:-1].std() + 1) # "+ 1" to avoid division by 0 #model rollingStd = SeriesTempsNorm.apply(lambda x : pd.rolling_std(x,window=window), axis = 0) scoreSeason = rollingStd.iloc[-1] / rollingStd.iloc[window-1] #division of the last element by the first no NaN (offset du to the computation of the rolling std) scoreYear = rollingStd.iloc[-1] / rollingStd.iloc[:-1].mean() #mean variance as denominator def mergeScore(scoreSeason, scoreYear): # we take the right score if scoreSeason == np.inf: # if the Seasonal score is inf, their is no seasonnality effect, we take the score over the past year to avoid inf score return scoreYear else: return min(scoreSeason,scoreYear) # else it might be a seasonnality effect, then we take the season score score = scoreSeason.combine(other = scoreYear, func= lambda x, y : mergeScore(x,y)) return score def groupedScore(SeriesTemps): # normalization SeriesTempsNorm=(SeriesTemps-SeriesTemps.mean())/(SeriesTemps[:-1].std() + 1) # "+ 1" to avoid division by 0 #model return SeriesTempsNorm[1:].std() / SeriesTempsNorm[:-1].std() def scores_computation(SeriesTemps,group,window): if group < 6: # compute the score with concidering seasonnality return score(SeriesTemps,window) else: # compute the score without considering seasonnality return groupedScore(SeriesTemps)