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 as NotImplementedError at the top of `agg_or_apply_list_like` when the target object's `axis` attribute equals 1. List-like agg/apply in pandas is only implemented for axis=0 (column-wise); requesting axis=1 (row-wise) on a list/dict of functions is not supported, so pandas fails fast.

Solutions

  1. Transpose first: `df.T.agg([...]).T`, performing the list-agg column-wise on the transpose.
  2. Use a row-wise callable with `df.apply(func, axis=1)` instead of a list of aggregators.
  3. Compute each aggregator separately with `axis=1` and concatenate: `pd.concat([df.agg(f, axis=1) for f in funcs], axis=1)`.

Example fix

// before
df.agg(['mean', 'sum'], axis=1)
// after
df.T.agg(['mean', 'sum']).T
Defensive patterns

Strategy: validation

Validate before calling

def list_agg_axis_safe(df, funcs, axis=0):
    if axis == 1:
        return df.T.agg(funcs).T
    return df.agg(funcs, axis=axis)

Type guard

def list_agg_axis_supported(axis) -> bool:
    return axis == 0

Try / catch

try:
    out = df.agg(funcs, axis=1)
except NotImplementedError as e:
    if 'axis other than 0' in str(e):
        out = df.T.agg(funcs).T
    else:
        raise

Prevention

When it happens

Trigger: `df.agg(['mean', 'sum'], axis=1)`, `df.apply([f1, f2], axis=1)`, or any list-like agg/apply routed through this method with `obj.axis == 1`.

Common situations: Developers assume symmetry: `df.mean(axis=1)` works, so `df.agg([...], axis=1)` should too. Or they reuse a column-wise agg spec on a transposed frame.

Related errors


AI-assisted analysis of pandas-dev/pandas@3b7651241d (2026-08-11). Data as JSON: /api/errors/04e3c986b2b90968. Report an issue: GitHub.

Appendix: 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 3b7651241d)