I often use method chaining in pandas, although certain problems like calculating the second most common value are hard. A really good solution to adding custom functionality in a chain is Pandas pipe function.
For example to raise a function to the 3rd power with numpy you could use
But another way with pipe is:
Note that you can pass any positional or keyword arguments and they'll get passed along.
df.pipe(f, *args, **kwargs) is equivalent to
f(df, *args, **kwargs).
If you build up a series of transforms on dataframes to dataframes you can then express this with a series of
It even works with a groupby.