On this page
pandas.Series.pipe
- Series.pipe(func, *args, **kwargs)[source]
-
Apply chainable functions that expect Series or DataFrames.
- Parameters
-
- func:function
-
Function to apply to the Series/DataFrame.
args
, andkwargs
are passed intofunc
. Alternatively a(callable, data_keyword)
tuple wheredata_keyword
is a string indicating the keyword ofcallable
that expects the Series/DataFrame. - args:iterable, optional
-
Positional arguments passed into
func
. - kwargs:mapping, optional
-
A dictionary of keyword arguments passed into
func
.
- Returns
-
- object:the return type of func.
See also
-
DataFrame.apply
-
Apply a function along input axis of DataFrame.
-
DataFrame.applymap
-
Apply a function elementwise on a whole DataFrame.
-
Series.map
-
Apply a mapping correspondence on a
Series
.
Notes
Use
.pipe
when chaining together functions that expect Series, DataFrames or GroupBy objects. Instead of writing>>> func(g(h(df), arg1=a), arg2=b, arg3=c)
You can write
>>> (df.pipe(h) ... .pipe(g, arg1=a) ... .pipe(func, arg2=b, arg3=c) ... )
If you have a function that takes the data as (say) the second argument, pass a tuple indicating which keyword expects the data. For example, suppose
f
takes its data asarg2
:>>> (df.pipe(h) ... .pipe(g, arg1=a) ... .pipe((func, 'arg2'), arg1=a, arg3=c) ... )
© 2008–2022, AQR Capital Management, LLC, Lambda Foundry, Inc. and PyData Development Team
Licensed under the 3-clause BSD License.
https://pandas.pydata.org/pandas-docs/version/1.5.0/reference/api/pandas.Series.pipe.html