Complete the code to select the data for the first level index 'A' from the MultiIndex DataFrame.
selected = df.loc[[1]]Using df.loc['A'] selects all rows where the first level of the MultiIndex is 'A'.
Complete the code to select data for the MultiIndex where the first level is 'B' and the second level is 'two'.
selected = df.loc[([1], 'two')]
Using df.loc[('B', 'two')] selects the row where the first level is 'B' and the second level is 'two'.
Fix the error in the code to select all rows where the second level index is 'one'.
selected = df.xs([1], level=1)
The xs method selects cross sections. Using xs('one', level=1) selects all rows where the second level index is 'one'.
Fill both blanks to create a dictionary comprehension that maps each word to its length only if the length is greater than 3.
lengths = {word: [1] for word in words if [2]The dictionary comprehension maps each word to its length using len(word). The condition len(word) > 3 filters words longer than 3 characters.
Fill all three blanks to create a dictionary comprehension that maps uppercase words to their counts only if the count is greater than 1.
result = [1]: [2] for [3], [2] in counts.items() if [2] > 1}}
The comprehension maps each uppercase word (word.upper()) to its count (count) only if the count is greater than 1. The loop variables are word and count.