Python Forum
AttributeError: (“module 'pandas' has no attribute 'rolling_std'” - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Data Science (https://python-forum.io/forum-44.html)
+--- Thread: AttributeError: (“module 'pandas' has no attribute 'rolling_std'” (/thread-21210.html)



AttributeError: (“module 'pandas' has no attribute 'rolling_std'” - Mariana136 - Sep-19-2019

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:
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)



RE: AttributeError: (“module 'pandas' has no attribute 'rolling_std'” - Larz60+ - Sep-20-2019

show error, verbatim


RE: AttributeError: (“module 'pandas' has no attribute 'rolling_std'” - Mariana136 - Sep-23-2019

Sorry. Here is the error:
Error:
--------------------------------------------------------------------------- AttributeError Traceback (most recent call last) <ipython-input-9-80eddc82c8d1> in <module> 1 ## Scores computation 2 print("Scores computation") ----> 3 Scores = scores.scores_computation(temporalSeries,group,window) 4 print("End of scores computation") ~\Desktop\AOD - VANZARI\AOD - discount\applicationAOD_20170911\application\scores.py in scores_computation(SeriesTemps, group, window) 32 if group < 6: 33 # compute the score with concidering seasonnality ---> 34 return score(SeriesTemps,window) 35 else: 36 # compute the score without considering seasonnality ~\Desktop\AOD - VANZARI\AOD - discount\applicationAOD_20170911\application\scores.py in score(SeriesTemps, window) 7 8 #model ----> 9 rollingStd = SeriesTempsNorm.apply(lambda x : pd.rolling_std(x,window=window), axis = 0) 10 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) 11 scoreYear = rollingStd.iloc[-1] / rollingStd.iloc[:-1].mean() #mean variance as denominator ~\AppData\Local\Continuum\anaconda3\New folder\lib\site-packages\pandas\core\frame.py in apply(self, func, axis, broadcast, raw, reduce, result_type, args, **kwds) 6485 args=args, 6486 kwds=kwds) -> 6487 return op.get_result() 6488 6489 def applymap(self, func): ~\AppData\Local\Continuum\anaconda3\New folder\lib\site-packages\pandas\core\apply.py in get_result(self) 149 return self.apply_raw() 150 --> 151 return self.apply_standard() 152 153 def apply_empty_result(self): ~\AppData\Local\Continuum\anaconda3\New folder\lib\site-packages\pandas\core\apply.py in apply_standard(self) 255 256 # compute the result using the series generator --> 257 self.apply_series_generator() 258 259 # wrap results ~\AppData\Local\Continuum\anaconda3\New folder\lib\site-packages\pandas\core\apply.py in apply_series_generator(self) 284 try: 285 for i, v in enumerate(series_gen): --> 286 results[i] = self.f(v) 287 keys.append(v.name) 288 except Exception as e: ~\Desktop\AOD - VANZARI\AOD - discount\applicationAOD_20170911\application\scores.py in <lambda>(x) 7 8 #model ----> 9 rollingStd = SeriesTempsNorm.apply(lambda x : pd.rolling_std(x,window=window), axis = 0) 10 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) 11 scoreYear = rollingStd.iloc[-1] / rollingStd.iloc[:-1].mean() #mean variance as denominator AttributeError: ("module 'pandas' has no attribute 'rolling_std'", 'occurred at index clasa BM<>B6')



RE: AttributeError: (“module 'pandas' has no attribute 'rolling_std'” - Larz60+ - Sep-23-2019

rolling_std has been depreciated from pandas, can still be used but syntax has changed
see: https://pandas.pydata.org/pandas-docs/stable/whatsnew/index.html


RE: AttributeError: (“module 'pandas' has no attribute 'rolling_std'” - Mariana136 - Sep-23-2019

I tried to replace
rollingStd = SeriesTempsNorm.apply(lambda x : pd.rolling_std(x,window=window), axis = 0)
with
rollingStd = SeriesTempsNorm.apply(lambda x : SeriesTemps.rolling(window=window).std(x), axis = 0)
but still doesn't work..