Resampler.pipe(self, func, *args, **kwargs)
[source]
Apply a function func
with arguments to this Resampler object and return the function’s result.
New in version 0.23.0.
Use .pipe
when you want to improve readability by chaining together functions that expect Series, DataFrames, GroupBy or Resampler objects. Instead of writing
>>> h(g(f(df.groupby('group')), arg1=a), arg2=b, arg3=c)
You can write
>>> (df.groupby('group') ... .pipe(f) ... .pipe(g, arg1=a) ... .pipe(h, arg2=b, arg3=c))
which is much more readable.
Parameters: |
|
---|---|
Returns: |
|
See also
Series.pipe
DataFrame.pipe
apply
See more here
>>> df = pd.DataFrame({'A': [1, 2, 3, 4]}, ... index=pd.date_range('2012-08-02', periods=4)) >>> df A 2012-08-02 1 2012-08-03 2 2012-08-04 3 2012-08-05 4
To get the difference between each 2-day period’s maximum and minimum value in one pass, you can do
>>> df.resample('2D').pipe(lambda x: x.max() - x.min()) A 2012-08-02 1 2012-08-04 1
© 2008–2012, 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/0.25.0/reference/api/pandas.core.resample.Resampler.pipe.html