Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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