推 woogee: df.groupby(df.index // 3).mean() 這樣是你要的嗎?05/29 23:04
感謝woogee大的回覆
可是我想要的是這樣
Value. Value1
0. 6. Nan
1. 5. Nan
2. 4. 2
3. 3. 2
4. 2. 2
5. 3. 0
就是原本的 df rolling(3)
每三個的頭尾想減 (6-4) (5-3)..
形成一個新的一個column這樣
感謝
※ 編輯: strekm (42.79.205.170 臺灣), 05/29/2022 23:32:57
推 celestialgod: 我推薦試試看polars 效能比較好 又比較多支援函數 05/29 23:33
推 lycantrope: 根本不用rolling 你想要的應該是shift(2)後相減 05/30 13:32
→ lycantrope: df["Val1"] = df["Val"].shift(2).sub(df["Val"]) 05/30 13:33
推 woogee: 哦哦,這樣的話,樓上l大的shift應該是正解 05/31 11:33
推 dtctvnvllvr: df.diff(2, axis=0) 06/26 00:21