pipe(self, func: 'Callable[..., T] | tuple[Callable[..., T], str]', *args, **kwargs) -> 'T'
Use :None:None:`.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) # doctest: +SKIP
You can write
>>> (df.groupby('group') ... .pipe(f) ... .pipe(g, arg1=a) ... .pipe(h, arg2=b, arg3=c)) # doctest: +SKIP
which is much more readable.
See more :None:None:`here
<https://pandas.pydata.org/pandas-docs/stable/user_guide/groupby.html#piping-function-calls>`
Function to apply to this GroupBy object or, alternatively, a :None:None:`(callable, data_keyword)`
tuple where :None:None:`data_keyword`
is a string indicating the keyword of :None:None:`callable`
that expects the GroupBy object.
Positional arguments passed into func
.
A dictionary of keyword arguments passed into func
.
Apply a function func
with arguments to this GroupBy object and return the function's result.
DataFrame.pipe
Apply a function with arguments to a dataframe.
Series.pipe
Apply a function with arguments to a series.
apply
Apply function to each group instead of to the full GroupBy object.
>>> df = pd.DataFrame({'A': 'a b a b'.split(), 'B': [1, 2, 3, 4]})
... df A B 0 a 1 1 b 2 2 a 3 3 b 4
To get the difference between each groups maximum and minimum value in one pass, you can do
This example is valid syntax, but we were not able to check execution>>> df.groupby('A').pipe(lambda x: x.max() - x.min()) B A a 2 b 2See :
Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.
Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)
SVG is more flexible but power hungry; and does not scale well to 50 + nodes.
All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them