Which groupby.agg form lets you name the output columns at the same time as choosing the aggregation?
Correct answer
B. Named aggregation, with keywords mapping each name to a column and func
15 views
B. Named aggregation, with keywords mapping each name to a column and func
15 views
Named aggregation takes keyword arguments such as total=('sales', 'sum'), so the aggregation and the output names are declared together and the result has a flat column index. The older dict-of-lists form returns MultiIndex columns that then need flattening, and a plain list of functions keeps the source column names. Named aggregation also avoids renaming MultiIndex columns by position, which is fragile.
Asked in: NTS, PPSC IT, Interviews
Not sure why the answer is B? Ask here and get an explanation.