df.pivot_table(index='dept', columns='month', values='sales') is called without aggfunc. What happens when several rows share a dept and month?
Correct answer
A. The duplicate cells are averaged, because the default aggregation is the mean
12 views
A. The duplicate cells are averaged, because the default aggregation is the mean
12 views
pivot_table defaults to aggfunc='mean', so repeated index-column pairs are averaged instead of raising the way DataFrame.pivot does on duplicates. Pass aggfunc='sum', or a list such as ['sum','count'], when totals are wanted. Forgetting the default silently reports averages in columns that look like counts.
Asked in: NTS, PPSC IT, Interviews
Not sure why the answer is A? Ask here and get an explanation.