python数据分析-区间频率统计

import numpy as np
import pandas as pd
ages = np.array([1,5,10,40,36,12,58,62,77,89,100,18,20,25,30,32]) #年龄数据
#s=pd.cut(ages, [0,5,20,30,50,100], labels=[u"婴儿",u"青年",u"中年",u"壮年",u"老年"])
#将ages分为了5个区间(0, 5],(5, 20],(20, 30],(30,50],(50,100].
s=pd.cut(ages, [0,5,20,30,50,100])
print(s.value_counts())
(0, 5]       2
(5, 20]      4
(20, 30]     2
(30, 50]     3
(50, 100]    5
dtype: int64
#统计频数
values = s.value_counts().values
print(values)
[2 4 2 3 5]

你可能感兴趣的:(python,python,numpy)