箱-使用箱龄对列值进行分类

时间:2019-02-14 22:13:11

标签: python pandas bins

我有一个.CSV文件,其片段如下所示:

ID,SN,          Age,Gender,Item ID,Item Name,               Price

0,Lisim78,       20, Male,  108,   Extraction Quickblade,    3.53
1,Lisovynya38,   40, Male,  143,   Frenzied Scimitar,        1.56
2,Ithergue48,    24, Male,   92,   Final Critic,             4.88
3,Chamassasya86, 24, Male,  100,   Blindscythe,              3.27
4,Iskosia90,     23, Male,  131,   Fury,                     1.44
5,Yalae81,       22, Male,   81,   Dreamkiss,                3.61
6,Itheria73,     36, Male,  169,   Interrogator,             2.18
7,Iskjaskst81,   20, Male,  162,   Abyssal Shard,            2.67
8,Undjask33,     22, Male,   21,   Souleater,                 1.1
9,Chanosian48,   35, Other, 136,   Ghastly Adamantite,       3.58
10,Inguron55,     23, Male,   95,   Singed Onyx Warscythe,    4.74 

我需要为“年龄”列建立分类,如下所示:

bins = [0, 10, 15, 20, 25, 30, 35, 40, 45]
names = ['<10', '10-14', '15-19', '20-24', '25-29', '30-34', '35-39', '40+']
df_bins = pd.cut(df['Age'], bins, labels=names)

如何使用垃圾箱对其他列(例如“ SN”列)进行分类?我希望能够统计'SN'栏中所有<10、10-14、15-19岁...等的玩家。

非常感谢您的帮助!

0 个答案:

没有答案