pandas.DataFrame.apply
pandas 3.1.1 · DataFrame · method
Apply a callable to one column at a time by default, or one row at a time with axis=1.
Call syntax
DataFrame.apply(…) Full signature
DataFrame.apply(
func,
axis=0,
raw=False,
result_type=None,
args=(),
by_row='compat',
engine=None,
engine_kwargs=None,
**kwargs,
)Run the example
Edit the example and select Run Python to see the result.
Parameters
| Parameter | Requirement | Accepted values and behavior |
|---|---|---|
func |
Required Positional or keyword |
function Supply a supported operation name or a callable, depending on this API. |
axis |
Optional Positional or keyword Default 0 |
{0 or 'index', 1 or 'columns'} Choose which axis the operation acts on. The accepted axis labels depend on the receiver. |
raw |
Optional Positional or keyword Default False |
bool Choose whether the callable receives NumPy arrays rather than pandas objects where supported. |
result_type |
Optional Positional or keyword Default None |
{'expand', 'reduce', 'broadcast', None} |
args |
Optional Positional or keyword Default () |
tuple |
by_row |
Optional Positional or keyword Default 'compat' |
False or "compat" |
engine |
Optional Positional or keyword Default None |
decorator or {'python', 'numba'} Choose the implementation that performs the operation. |
engine_kwargs |
Optional Positional or keyword Default None |
dict Pass a dictionary of options to the selected engine. |
**kwargs |
Optional Additional keyword arguments |
Returns
Series or DataFrame