0
0
Pandasdata~10 mins

xs() for cross-section selection in Pandas - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to select the cross-section for index label 'B' using xs().

Pandas
result = df.[1]('B')
Drag options to blanks, or click blank then click option'
Axs
Bloc
Ciloc
Dat
Attempts:
3 left
💡 Hint
Common Mistakes
Using loc or iloc instead of xs.
Trying to use at which selects a single value, not a cross-section.
2fill in blank
medium

Complete the code to select the cross-section for column 'score' using xs() on columns axis.

Pandas
result = df.[1]('score', axis=1)
Drag options to blanks, or click blank then click option'
Aat
Bloc
Ciloc
Dxs
Attempts:
3 left
💡 Hint
Common Mistakes
Not specifying axis=1 and getting row selection instead.
Using loc or iloc instead of xs.
3fill in blank
hard

Fix the error in the code to select the cross-section for index label 'C' in a multi-index DataFrame.

Pandas
result = df.[1](('C', 'second'))
Drag options to blanks, or click blank then click option'
Aat
Bxs
Ciloc
Dloc
Attempts:
3 left
💡 Hint
Common Mistakes
Using loc or iloc which may not work correctly with multi-index tuples.
Not passing the tuple correctly.
4fill in blank
hard

Fill both blanks to select the cross-section for index label 'A' at level 0 in a multi-index DataFrame.

Pandas
result = df.[1]('A', level=[2])
Drag options to blanks, or click blank then click option'
Axs
Bloc
C1
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using loc instead of xs for level selection.
Using wrong level number.
5fill in blank
hard

Fill all three blanks to select the cross-section for column 'score' at level 1 in a multi-index DataFrame.

Pandas
result = df.[1]('score', axis=[2], level=[3])
Drag options to blanks, or click blank then click option'
Aloc
B1
Dxs
Attempts:
3 left
💡 Hint
Common Mistakes
Using loc instead of xs.
Not specifying axis=1 for columns.
Wrong level number.