Pandas: Add cut as a Series method

Created on 11 Oct 2019  路  3Comments  路  Source: pandas-dev/pandas

Problem description

It would be to have cut as a series method so that we can method chain. Currently, we must use pd.cut, for example,

filled_series = df.some_series.fillna(0)
pd.cut(filled_series, 10).mean()

it would be nice to do,

df.some_series.fillna(0).cut(10).mean()

This would also help hugely with tab completion.

Expected Output

To have a tab-completed series method for cut.

API Design Enhancement Needs Discussion Series cut

Most helpful comment

take

All 3 comments

I'd be -0 on adding cut as a method. cut can currently return an ndarray, tuple, Categorical, or Series which is not conducive to chaining which would be an advantage of having cut as a method.

@mroeschke cut, the pandas function, behaves like this, but could cut, the series method, not just have a subset of behaviours. If you're using the cut method on a series you aren't likely bothered about it returning anything other than a series.

If I'm reading the docs correctly, it is always series in - series out, given retbins is False (which is the default).

What are your thoughts on this?

take

Was this page helpful?
0 / 5 - 0 ratings

Related issues

venuktan picture venuktan  路  3Comments

MatzeB picture MatzeB  路  3Comments

scls19fr picture scls19fr  路  3Comments

Abrosimov-a-a picture Abrosimov-a-a  路  3Comments

ericdf picture ericdf  路  3Comments