Created
September 26, 2020 08:56
-
-
Save yuyasugano/fdc208d1c2c8ac3084882ace6d320325 to your computer and use it in GitHub Desktop.
Pandas DataFrame tips
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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