python分箱分类代码_分箱统计,数据频率统计,数据分类

import pandas as pd

score_list = [63, 67, 73, 84, 88, 97, 70, 85, 68, 96, 95, 60, 83, 70, 77, 86, 83, 94, 100, 82]

print(score_list)

bins = [50,70,90,100]

res = pd.cut(score_list, bins)

res1 = pd.cut(score_list, bins, labels=["及格","中等","优秀"])

print(res)

print("---"*35)

print(res1)

#################################################

"""

[63, 67, 73, 84, 88, 97, 70, 85, 68, 96, 95, 60, 83, 70, 77, 86, 83, 94, 100, 82]

[(50, 70], (50, 70], (70, 90], (70, 90], (70, 90], ..., (70, 90], (70, 90], (90, 100], (90, 100], (70, 90]]

Length: 20

Categories (3, interval[int64]): [(50, 70] < (70, 90] < (90, 100]]

---------------------------------------------------------------------------------------------------------

[及格, 及格, 中等, 中等, 中等, ..., 中等, 中等, 优秀, 优秀, 中等]

Length: 20

Categories (3, object): [及格 < 中等 < 优秀]

"""

你可能感兴趣的:(python分箱分类代码)