Skip to content

Commit ef5d803

Browse files
code sample for pandas-dev#41760
1 parent c16356e commit ef5d803

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

bisect/41760.py

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import pandas as pd
2+
3+
print(pd.__version__)
4+
5+
d = {
6+
"num_legs": [4, 4, 2, 2, 8],
7+
"num_wings": [0, 0, 2, 2, 0],
8+
"class": ["mammal", "mammal", "mammal", "bird", "insect"],
9+
"animal": ["cat", "dog", "bat", "penguin", "spider"],
10+
"locomotion": ["walks", "walks", "flies", "walks", "walks"],
11+
}
12+
df = pd.DataFrame(data=d)
13+
df = df.set_index(["class", "animal", "locomotion"])
14+
df = df.transpose()
15+
print(df)
16+
17+
result = df.xs(["mammal", "bird"], drop_level=False, axis=1)
18+
print(result)

0 commit comments

Comments
 (0)