Complete the code to select the cross-section for index label 'B' using xs().
result = df.[1]('B')
The xs() method selects a cross-section from the DataFrame by label. Here, df.xs('B') selects the row with index label 'B'.
Complete the code to select the cross-section for column 'score' using xs() on columns axis.
result = df.[1]('score', axis=1)
The xs() method can select cross-sections along columns by setting axis=1. Here, df.xs('score', axis=1) selects the column named 'score'.
Fix the error in the code to select the cross-section for index label 'C' in a multi-index DataFrame.
result = df.[1](('C', 'second'))
For multi-index DataFrames, xs() can select cross-sections by passing a tuple of index labels. Here, df.xs(('C', 'second')) selects the row with index ('C', 'second').
Fill both blanks to select the cross-section for index label 'A' at level 0 in a multi-index DataFrame.
result = df.[1]('A', level=[2])
The xs() method can select cross-sections at a specific level in a multi-index by using the level parameter. Here, df.xs('A', level=0) selects all rows where the first level index is 'A'.
Fill all three blanks to select the cross-section for column 'score' at level 1 in a multi-index DataFrame.
result = df.[1]('score', axis=[2], level=[3])
To select a cross-section of columns in a multi-index DataFrame, use xs() with axis=1 and specify the level. Here, df.xs('score', axis=1, level=1) selects the 'score' column at the second level of the columns multi-index.