buckets python pandas code example

Example 1: difference between cut and qcut pandas

pd.interval_range(start=0, freq=10000, end=200000, closed='left')

#res
IntervalIndex([[0, 10000), [10000, 20000), [20000, 30000), [30000, 40000), [40000, 50000) ... [150000, 160000),
[160000, 170000), [170000, 180000), [180000, 190000), [190000, 200000)],
              closed='left',
              dtype='interval[int64]')

Example 2: 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.