Skip to content

Commit 103fb7c

Browse files
code sample for pandas-dev#38523
1 parent f040b46 commit 103fb7c

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

bisect/38523.py

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import pandas as pd
2+
3+
print(pd.__version__)
4+
5+
arrays = [
6+
["Falcon", "Falcon", "Parrot", "Parrot"],
7+
["Captive", "Wild", "Captive", "Wild"],
8+
]
9+
index = pd.MultiIndex.from_arrays(arrays, names=("Animal", "Type"))
10+
df = pd.DataFrame({"Max Speed": [390.0, 350.0, 30.0, 20.0]}, index=index)
11+
12+
result = df.groupby(level=0)["Max Speed"].rolling(2).sum()
13+
print(result)
14+
15+
expected = pd.MultiIndex.from_tuples(
16+
[
17+
("Falcon", "Falcon", "Captive"),
18+
("Falcon", "Falcon", "Wild"),
19+
("Parrot", "Parrot", "Captive"),
20+
("Parrot", "Parrot", "Wild"),
21+
],
22+
names=["Animal", "Animal", "Type"],
23+
)
24+
25+
import pandas.testing as tm
26+
27+
tm.assert_index_equal(result.index, expected)

0 commit comments

Comments
 (0)