Series.
pipe
Apply func(self, *args, **kwargs).
Function to apply to the Series/DataFrame. args, and kwargs are passed into func. Alternatively a (callable, data_keyword) tuple where data_keyword is a string indicating the keyword of callable that expects the Series/DataFrame.
args
kwargs
func
(callable, data_keyword)
data_keyword
callable
Positional arguments passed into func.
A dictionary of keyword arguments passed into func.
See also
DataFrame.apply
DataFrame.applymap
Series.map
Notes
Use .pipe when chaining together functions that expect Series, DataFrames or GroupBy objects. Instead of writing
.pipe
>>> f(g(h(df), arg1=a), arg2=b, arg3=c)
You can write
>>> (df.pipe(h) ... .pipe(g, arg1=a) ... .pipe(f, 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 as arg2:
f
arg2
>>> (df.pipe(h) ... .pipe(g, arg1=a) ... .pipe((f, 'arg2'), arg1=a, arg3=c) ... )