简体   繁体   中英

Pandas DataFrame reversed rolling window

Is there any way I can preform a reversed rolling window without needing to reverse the column?

I am preforming a window normalization and for my implementation it is critical that the window will roll starting at the end while going up every step leaving the new value at the bottom cell. I attached the current sate of my implementation:

dataframe['std']  = dataframe['temperature'].rolling(window=24).std()
dataframe['mean'] = dataframe['temperature'].rolling(window=24).mean()  
dataframe['normed'] = (dataframe['temperature'] - dataframe['mean']) / dataframe['std']

my problem with it is that the normalized value is calculated using future measurements. the only solution I came up with is reverse the column and doing the same operations i did before then reversing it again. the problem with it is that it might take a long time and i want to create an efficient algorithm.

based on link1 , link2 , link3 you would get away with df["column_name"][::-1] or something similar

Also: you can use .rolling(num).agg(["mean", "std"]) to go through dataframe once

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM