根据数据分析对象的特征,按照一定的数值指标,把数据分析对象划分为不同的区间进行研究,以揭示其内在联系和规律性。 cut 函数: cut(series,bins,right=True,labels=NULL) ① series 需要分组的数据 ② bins 分组的划分数组 ③ right 分组的时候,右边是否闭合,默认为闭合True ④ labels 分组的自定义标签,可以不自定义
import pandas
data = pandas.read_csv(
'D:\\PDA\\4.15\\data.csv',
sep='|'
)
#理解为什么我的bins区间要-1和+1
bins = [
min(data.cost)-1, 20, 40, 60,
80, 100, max(data.cost)+1
]
data['cut'] = pandas.cut(
data.cost,
bins
)
data['cut'] = pandas.cut(
data.cost,
bins,
right=False
)
labels = [
'20以下', '20到40', '40到60',
'60到80', '80到100', '100以上'
]
data['cut'] = pandas.cut(
data.cost, bins,
right=False, labels=labels
)
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有