Skip to content

Instantly share code, notes, and snippets.

@yuyasugano
Created September 26, 2020 08:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yuyasugano/fdc208d1c2c8ac3084882ace6d320325 to your computer and use it in GitHub Desktop.
Save yuyasugano/fdc208d1c2c8ac3084882ace6d320325 to your computer and use it in GitHub Desktop.
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