pandas-dev/pandas · error · NotImplementedError
axis other than 0 is not supported
Error message
axis other than 0 is not supported
What it means
Raised in `agg_or_apply_list_like` when the object's axis attribute is 1 (column-wise operation) for a list-like agg/apply path that only supports axis=0. List-like aggregation iterates columns, so the implementation deliberately rejects axis=1 to avoid surprising behavior.
Source
Thrown at pandas/core/apply.py:882
def agg_or_apply_list_like(
self, op_name: Literal["agg", "apply"]
) -> DataFrame | Series:
obj = self.obj
kwargs = self.kwargs
if op_name == "apply":
if isinstance(self, FrameApply):
by_row = self.by_row
elif isinstance(self, SeriesApply):
by_row = "_compat" if self.by_row else False
else:
by_row = False
kwargs = {**kwargs, "by_row": by_row}
if getattr(obj, "axis", 0) == 1:
raise NotImplementedError("axis other than 0 is not supported")
if op_name == "agg" and isinstance(self, FrameApply):
result = self._agg_list_like_frame_reductions()
if result is not None:
return result
keys, results = self.compute_list_like(op_name, obj, kwargs)
result = self.wrap_results_list_like(keys, results)
return result
def agg_or_apply_dict_like(
self, op_name: Literal["agg", "apply"]
) -> DataFrame | Series:
assert op_name in ["agg", "apply"]
obj = self.obj
kwargs = {}
if op_name == "apply":View on GitHub (pinned to 71959b8cb9)
Solutions
- Drop axis=1 and let agg operate column-wise (axis=0), which is the only supported direction for list-like func.
- Transpose the frame: `df.T.agg(['sum', 'mean']).T` if you genuinely need row-wise reduction.
- Use `df.apply(func, axis=1)` with a single function that internally computes multiple stats, returning a Series.
Example fix
# before df.agg(['sum', 'mean'], axis=1) # after df.T.agg(['sum', 'mean']).T
Defensive patterns
Strategy: validation
Validate before calling
def safe_list_agg(df, funcs, axis=0):
if axis == 1:
raise NotImplementedError('list-like agg supports axis=0 only; use df.T')
return df.agg(funcs, axis=axis) Type guard
def is_axis0_or_transposable(axis) -> bool:
return axis == 0 Try / catch
try:
df.agg(funcs, axis=1)
except NotImplementedError as e:
if 'axis other than 0' in str(e):
df.T.agg(funcs).T
else:
raise Prevention
- Do not pass axis=1 with list-like agg; transpose the frame instead.
- Keep a helper for row-wise multi-stat reduction.
When it happens
Trigger: `df.agg(['sum', 'mean'], axis=1)` — list-like func with axis=1. The check at apply.py:881 (`getattr(obj, 'axis', 0) == 1`) fires.
Common situations: Copy-pasting axis=1 from a single-function apply call into a list-based agg; assuming axis symmetry across all agg surfaces; refactoring from row-wise apply to list-agg without dropping axis.
Related errors
- cannot perform both aggregation and transformation operation
- Operation {func} does not support axis=1
- The 'numba' engine doesn't support list-like/dict likes of c
- nested renamer is not supported
- Label(s) {list(cols)} do not exist
AI-assisted analysis of pandas-dev/pandas@71959b8cb9 (2026-08-07).
Data as JSON: /api/errors/04e3c986b2b90968.
Report an issue: GitHub.