我在Python- Jupyter中的代码中发生错误。我是python的新手。 这是代码:
```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)
使用pd.rolling_std时发生错误。我不知道为什么它不起作用,因为我之前使用过这段代码,并且效果很好。 有人知道会发生什么吗? 我看到了相同问题的答案,但对我来说不起作用。
谢谢