Skip to main contentSkip to solution

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.

Keyboard Shortcuts

  • Left arrow: Previous question
  • Right arrow: Next question
  • S key: Jump to solution
  • Q key: Jump to question