問題文
A dataframe has a category column and a numeric amount column. Which pair of operations produces the total amount for each category?
選択肢
- Set the category column as the index and call the summary-statistics method, so the totals arrive as one of its rows.
- Sort the dataframe by the category column and then take a cumulative sum of the amount column, because sorting places identical categories next to each other and the running total then gives the per-category figure directly.
- Group the dataframe by the category column and then apply a sum aggregation to the amount column.
- Filter the dataframe once per category and sum each result, so the full table is scanned once for every category present.