pandas-dev/pandas · error · ValueError

Operation {func} does not support axis=1

Error message

Operation {func} does not support axis=1

What it means

Raised inside `apply_str` when the user calls a string-named method on axis=1 but that method does not accept an `axis` argument (or is one of the excluded methods like 'corrwith'/'skew'). Most DataFrame methods are column-oriented (axis=0); applying them across rows is unsupported for these specific names.

Source

Thrown at pandas/core/apply.py:737

        obj = self.obj

        from pandas.core.groupby.generic import (
            DataFrameGroupBy,
            SeriesGroupBy,
        )

        # Support for `frame.transform('method')`
        # Some methods (shift, etc.) require the axis argument, others
        # don't, so inspect and insert if necessary.
        method = getattr(obj, func, None)
        if callable(method):
            sig = inspect.getfullargspec(method)
            arg_names = (*sig.args, *sig.kwonlyargs)
            if self.axis != 0 and (
                "axis" not in arg_names or func in ("corrwith", "skew")
            ):
                raise ValueError(f"Operation {func} does not support axis=1")
            if "axis" in arg_names and not isinstance(
                obj, (SeriesGroupBy, DataFrameGroupBy)
            ):
                self.kwargs["axis"] = self.axis
        return self._apply_str(obj, func, *self.args, **self.kwargs)

    def apply_list_or_dict_like(self) -> DataFrame | Series:
        """
        Compute apply in case of a list-like or dict-like.

        Returns
        -------
        result: Series, DataFrame, or None
            Result when self.func is a list-like or dict-like, None otherwise.
        """

        if self.engine == "numba":
            raise NotImplementedError(

View on GitHub (pinned to 71959b8cb9)

Solutions

  1. Call the method directly without axis, or operate on `df.T` and translate back: `getattr(df.T, func)().T`.
  2. Drop axis=1 for methods that are inherently column-oriented.
  3. For 'corrwith'/'skew', use the dedicated method with axis=0 or transpose the frame.

Example fix

# before
df.apply('corrwith', axis=1, other=other)
# after
df.T.corrwith(other.T).T  # or restructure to axis=0
Defensive patterns

Strategy: validation

Validate before calling

import inspect

def supports_axis1_str(df, func_name):
    method = getattr(df, func_name, None)
    if not callable(method):
        return False
    spec = inspect.getfullargspec(method)
    return 'axis' in (*spec.args, *spec.kwonlyargs) and func_name not in ('corrwith', 'skew')

if supports_axis1_str(df, 'sum'):
    df.apply('sum', axis=1)

Type guard

def is_axis1_supported(df, func_name) -> bool:
    return supports_axis1_str(df, func_name)

Try / catch

try:
    df.apply(func_name, axis=1)
except ValueError as e:
    if 'does not support axis=1' in str(e):
        getattr(df.T, func_name)().T
    else:
        raise

Prevention

When it happens

Trigger: `df.apply('corrwith', axis=1)`, `df.apply('skew', axis=1)` (excluded explicitly), or `df.apply('<method_without_axis_param>', axis=1)` where the method signature lacks an `axis` parameter.

Common situations: Auto-dispatching a list of method names against axis=1 generically; misremembering which methods support row-wise operation; version changes that removed axis support from a method.

Related errors


AI-assisted analysis of pandas-dev/pandas@71959b8cb9 (2026-08-07). Data as JSON: /api/errors/1adcd6b541890744. Report an issue: GitHub.