Python Forum
AttributeError: (“module 'pandas' has no attribute 'rolling_std'”
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
AttributeError: (“module 'pandas' has no attribute 'rolling_std'”
#1
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)
Reply
#2
show error, verbatim
Reply
#3
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')
Reply
#4
rolling_std has been depreciated from pandas, can still be used but syntax has changed
see: https://pandas.pydata.org/pandas-docs/st...index.html
Reply
#5
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..
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Python Custom Module not working in Jupyter Notebook with Pandas fid 0 1,464 Jul-04-2020, 11:05 AM
Last Post: fid
  AttributeError: module 'numpy' has no attribute 'array aapurdel 7 39,500 May-29-2019, 02:48 AM
Last Post: heiner55
  Pandas to_csv in for loop AttributeError: 'tuple' object has no attribute 'to_csv' NSearch 9 13,512 Apr-22-2019, 05:05 PM
Last Post: Yoriz
  AttributeError: 'NoneType' object has no attribute 'all' synthex 2 4,281 Mar-07-2019, 11:11 AM
Last Post: synthex
  Please help with AttributeError: 'Netz' object has no attribute 'conv' DerBerliner 2 2,748 Feb-27-2019, 06:01 PM
Last Post: DerBerliner
  AttributeError: Can't get attribute 'Individual' on <module 'deap.creator' DomClout 4 7,033 Jul-27-2018, 09:05 PM
Last Post: Vysero
  AttributeError: module 'mnist' has no attribute 'train_images' pythonbeginner 1 6,959 Jun-14-2018, 09:29 PM
Last Post: snippsat
  AttributeError: 'set' object has no attribute 'items hey_arnold 3 24,388 Apr-29-2018, 04:33 PM
Last Post: hey_arnold
  AttributeError: module 'plotly' has no attribute 'offline' charlesczc 8 14,703 Jan-21-2018, 08:34 AM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020