'Complete windows in pandas rolling
I'm trying to create complete windows using the rolling function of pandas (a complete window is a window with the same size as the window argument of the rolling function).
Consider the following code snippet -
df = pd.DataFrame({'X': [1]*10,
'Y': 'a'})
df.loc[5:,'Y'] = 'b'
which yields the following dataframe-
X Y
0 1 a
1 1 a
2 1 a
3 1 a
4 1 a
5 1 b
6 1 b
7 1 b
8 1 b
9 1 b
Iterating the 3 elements size windows-
for win in df.groupby(["Y"]).rolling(3):
print(win.shape[0])
1
2
3
3
3
1
2
3
3
3
Is it possible to get only 3 length size windows without using a win.shape[0] == 3 condition?
Thanks a lot.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
