Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Pandas DataFrame tips
import pandas as pd
df = pd.DataFrame(range(10), columns=['num'])
print(df)
num
0 0
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
print(df.rolling(3)) # Rolling object
print(type(df.rolling(3))) # This is pandas.core.window.rolling.Rolling class
Rolling [window=3,center=False,axis=0]
<class 'pandas.core.window.rolling.Rolling'>
print(df.rolling(3).sum())
num
0 NaN
1 NaN
2 3.0
3 6.0
4 9.0
5 12.0
6 15.0
7 18.0
8 21.0
9 24.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment