What is the default axis value for the operations like sum() in pandas?
What is the default axis value for the operations like sum() in pandas?
Solution
✅ Correct Option: 1
In pandas, aggregation methods such as sum(), mean(), min() and max() use axis=0 by default. They work down the rows (the index) and return one result for each column.
For a DataFrame, df.sum() gives column totals, while df.sum(axis=1) gives row totals.
Option 2: axis=1 gives row-wise totals, but it must be passed explicitly.
Option 3: a DataFrame has only two axes (0 and 1), so axis=2 raises an error.
Option 4: a default axis does exist, and it is 0.
Related questions:
2025: 21 May Shift 1
2026: 29 May Shift 1