Why can't I apply shift from within a pandas function?

前端 未结 3 1787
陌清茗
陌清茗 2020-12-21 08:26

I am trying to build a function that uses .shift() but it is giving me an error. Consider this:

In [40]:

data={\'level1\':[20,19,20,21,25,29,30,31,30,29,31]         


        
3条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-21 08:51

    Check if the values you are trying to shift is not an array. Then you need to convert the array to series. With this you will be able to shift the values. I was having same issues,now I am able to get the shift values.

    This is my part of the code for your reference.

    X = grouped['Confirmed_day'].values
    X_series=pd.Series(X)
    
    X_lag1 = X_series.shift(1)
    

提交回复
热议问题