We can use pd.cut
to bin the values into ranges, then we can groupby
these ranges, and finally call count
to count the values now binned into these ranges:
np.random.seed(0)
df = pd.DataFrame({"a": np.random.random_integers(1, high=100, size=100)})
ranges = [0,10,20,30,40,50,60,70,80,90,100]
df.groupby(pd.cut(df.a, ranges)).count()
a
a
(0, 10] 11
(10, 20] 10
(20, 30] 8
(30, 40] 13
(40, 50] 11
(50, 60] 9
(60, 70] 10
(70, 80] 11
(80, 90] 13
(90, 100] 4
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…