bins = 7 _, edges = pd.cut(df.value, bins=bins, retbins=True) labels = [f'({abs(edges[i]):.0f}, {edges[i+1]:.0f}]' for i in range(len(edges)-1)] df['bin'] = pd.cut(df.value, bins=bins, labels=labels) # value bin # 1 8 (0, 53] # 2 16 (0, 53] # .. ... ... # 45 360 (322, 376] # 46 368 (322, 376]
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter