df[‘PriceBin’] = pd.cut(df[‘PriceAvg’], bins = 3)
df[‘PriceBin’].value_counts()
(54060.0, 2040000.0] 209
(2040000.0, 4020000.0] 4
(4020000.0, 6000000.0] 1
Name: PriceBin, dtype: int64
df[‘PriceBin’] = pd.qcut(df[‘PriceAvg’], q=3)
df[‘PriceBin’].value_counts().sort_index()
(59999.999, 210000.0] 77 (210000.0, 315000.0] 66 (315000.0, 6000000.0] 71 Name: PriceBin, dtype: int64
h = df.groupby(‘PriceBin’, as_index=False).median()[‘SalesAvg’]
h = pd.DataFrame(h)
h.reset_index(inplace=True)
h
PriceBin SalesAvg
0(59999.999, 210000.0] 42.0000001
(210000.0, 315000.0] 145.1666672
(315000.0, 6000000.0] 114.200000