Quiz: Reshaping, Pivot Tables, Aggregations

Quiz yourself on reshaping, pivot tables, and aggregations.

1

Look at the given DataFrame df:

      name   age   rank  week        
0     Alice  12    3     44    
1     Bob    8     4     44
2     Carl   10    5     45
3     Carl   10    2     45
4     Bob    8     5     45

We want to create a pivot table. What will be the output of following command?

pd.pivot_table(
data = df,
values = rank,
index = 'name',
columns = 'week',
aggfunc = 'sum',
margins = True,
margins_name = 'Total'
)
A)
week    44    45    Total    
name
Alice   3     NaN    NaN
Bob     4     5      9
Carl    NaN   7      NaN
Total   NaN   NaN    NaN
B)
week    44    45    Total    
name
Alice   3     NaN    3
Bob     4     5      9
Carl    NaN   7      7
Total   7     12     19
C)
week    44    45    Total    
name
Alice   3     NaN   3
Bob     4     5     9
Carl    NaN   7     7
D)
week    44   45    
name
Alice   3    NaN    
Bob     4    5    
Carl    NaN  7    
Total   7    12
Question 1 of 50 attempted

Get hands-on with 1200+ tech skills courses.