pandas-dev/pandas · error · ValueError
Operation does not support axis=1
Error message
Operation {func} does not support axis=1 What it means
Raised in `apply_str` (the string-dispatch path) when the user passes `axis=1` to a method that either has no `axis` parameter on its signature or is explicitly excluded (`corrwith`, `skew`). Pandas inspects the method's fullargspec; if `axis` is not accepted (or the method is on the exclusion list) it cannot honor `axis=1` and raises immediately rather than silently running along the wrong axis.
Solutions
- Drop the `axis=1` argument for methods that only operate column-wise (corrwith, skew without axis support).
- For row-wise skew, call `df.skew(axis=1)` directly on the DataFrame instead of through apply.
- If you need a row-wise custom op, pass a callable (not a string) to `df.apply(..., axis=1)`.
Example fix
// before
df.apply('skew', axis=1)
// after
df.skew(axis=1) Defensive patterns
Strategy: validation
Validate before calling
AXIS1_BLOCKED = {'corrwith', 'skew'}
def apply_str_axis1_safe(df, func, axis=0):
import inspect
if axis == 1 and isinstance(func, str):
method = getattr(df, func, None)
if method is None:
raise ValueError(f'{func} not found on DataFrame')
sig = inspect.getfullargspec(method)
arg_names = (*sig.args, *sig.kwonlyargs)
if 'axis' not in arg_names or func in AXIS1_BLOCKED:
raise ValueError(f'{func} does not support axis=1; call directly or drop axis')
return df.apply(func, axis=axis) Type guard
def str_method_supports_axis1(df, func) -> bool:
import inspect
if func in ('corrwith', 'skew'):
return False
m = getattr(df, func, None)
if not callable(m):
return False
spec = inspect.getfullargspec(m)
return 'axis' in (*spec.args, *spec.kwonlyargs) Try / catch
try:
out = df.apply(func, axis=1)
except ValueError as e:
if 'does not support axis=1' in str(e):
out = getattr(df, func)() # fall back to default axis
else:
raise Prevention
- Prefer calling stats methods directly (df.skew()) over apply-with-strings.
- Maintain a project-level allowlist of axis=1-compatible string methods.
- Avoid passing axis=1 to apply-with-string globally.
When it happens
Trigger: Calls like `df.apply('corrwith', axis=1)`, `df.apply('skew', axis=1)`, or `df.apply('<method_without_axis_param>', axis=1)`. Common with frame.transform('method', axis=1) routing through the same path.
Common situations: Passing axis=1 globally to a pipeline that calls apply with method-name strings; misremembering which stats methods support row-wise operation; migrating code from axis=0 default to row-wise and assuming all methods comply.
Related errors
- axis other than 0 is not supported
- by_row= not allowed
- cannot broadcast result
- cannot diff on axis=
- Column is backed by an extension array, which is not…
AI-assisted analysis of pandas-dev/pandas@3b7651241d (2026-08-11).
Data as JSON: /api/errors/1adcd6b541890744.
Report an issue: GitHub.
Appendix: 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 3b7651241d)