equal depth binning pandas code example
Example 1: difference between cut and qcut pandas
interval_range = pd.interval_range(start=0, freq=10000, end=200000)
df['cut_ex2'] = pd.cut(df['ext price'], bins=interval_range, labels=[1,2,3])
df.head()
#There is a downside to using interval_range . You can not define custom labels.
Example 2: difference between cut and qcut pandas
\
df['quantile_ex_4'] = pd.qcut(df['ext price'],
q=[0, .2, .4, .6, .8, 1], #quartiles bin range will vary
labels=False, #returns integers as categories
precision=0)
df.head()
#all bins will have roughly same no. of observation