我有以下代码:
import pandas as pd
# Sample DataFrame
df = pd.DataFrame({'clicks': [i for i in range(1000)]})
# Calculate the max of the next 140 rows for each row
roll = df['clicks'].rolling(window=141, min_periods=1).max()
print(roll)
但它没有返回预期的输出:
0 141.0
1 142.0
2 143.0
3 144.0
4 145.0
但它输出:
0 0.0
1 1.0
2 2.0
3 3.0
4 4.0
我做错了什么?
1条答案
按热度按时间qrjkbowd1#
您需要将其向前移动140行,以便窗口 * 包括接下来的140行 *,而不仅仅是第一行,第二行,第三行等,直到999行。