Skip to content

Commit 23bcfab

Browse files
add code sample for pandas-dev#35869
1 parent 1a121e6 commit 23bcfab

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

bisect/35869.py

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import numpy as np
2+
import pandas as pd
3+
import pandas.testing as tm
4+
5+
print(pd.__version__)
6+
7+
df = pd.DataFrame(
8+
{
9+
"column1": range(6),
10+
"column2": range(6),
11+
"group": 3 * ["A", "B"],
12+
"date": pd.date_range(end="20190101", periods=6),
13+
}
14+
)
15+
df
16+
17+
res = df.groupby("group").rolling("3d", on="date")["column1"].count()
18+
print(res)
19+
20+
expected = pd.Series(
21+
np.array([1.0, 2.0, 2.0, 1.0, 2.0, 2.0]),
22+
pd.MultiIndex.from_arrays(
23+
[
24+
["A"] * 3 + ["B"] * 3,
25+
pd.DatetimeIndex(
26+
[
27+
"2018-12-27",
28+
"2018-12-29",
29+
"2018-12-31",
30+
"2018-12-28",
31+
"2018-12-30",
32+
"2019-01-01",
33+
],
34+
dtype="datetime64[ns]",
35+
),
36+
],
37+
names=["group", "date"],
38+
),
39+
name="column1",
40+
)
41+
42+
tm.assert_series_equal(res, expected)
43+

0 commit comments

Comments
 (0)