Skip to content

Instantly share code, notes, and snippets.

@yuyasugano
Created September 26, 2020 10:29
Show Gist options
  • Save yuyasugano/585c465de7fe60fda8d9c40bbbe872b0 to your computer and use it in GitHub Desktop.
Save yuyasugano/585c465de7fe60fda8d9c40bbbe872b0 to your computer and use it in GitHub Desktop.
Pandas DataFrame tips
print(df.rolling(3).apply(lambda x: sum(x)-min(x)))
num
0 NaN
1 NaN
2 3.0
3 5.0
4 7.0
5 9.0
6 11.0
7 13.0
8 15.0
9 17.0
print(df.rolling(3).agg([sum, min, lambda x: sum(x)-min(x)]))
sum min <lambda>
0 NaN NaN NaN
1 NaN NaN NaN
2 3.0 0.0 3.0
3 6.0 1.0 5.0
4 9.0 2.0 7.0
5 12.0 3.0 9.0
6 15.0 4.0 11.0
7 18.0 5.0 13.0
8 21.0 6.0 15.0
9 24.0 7.0 17.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment