内容简介:5214
import numpy as np from pandas import Series,DataFrame import pandas as pd # 使用pandas的cut函数划分年龄组 ages = [20,22,25,27,21,23,37,31,61,45,32] bins = [18,25,35,60,100] cats = pd.cut(ages,bins) print(cats) [(18, 25], (18, 25], (18, 25], (25, 35], (18, 25], ..., (35, 60], (25, 35], (60, 100], (35, 60], (25, 35]] Length: 11 Categories (4, interval[int64]): [(18, 25] < (25, 35] < (35, 60] < (60, 100]] cats.codes array([0, 0, 0, 1, 0, 0, 2, 1, 3, 2, 1], dtype=int8) pd.value_counts(cats) (18, 25] 5 (25, 35] 3 (35, 60] 2 (60, 100] 1 dtype: int64 pd.cut(ages,bins,right=False) [[18, 25), [18, 25), [25, 35), [25, 35), [18, 25), ..., [35, 60), [25, 35), [60, 100), [35, 60), [25, 35)] Length: 11 Categories (4, interval[int64]): [[18, 25) < [25, 35) < [35, 60) < [60, 100)] group_names = ['Youth','YoungAdult','MiddleAged','Senior'] pd.cut(ages,bins,labels=group_names) [Youth, Youth, Youth, YoungAdult, Youth, ..., MiddleAged, YoungAdult, Senior, MiddleAged, YoungAdult] Length: 11 Categories (4, object): [Youth < YoungAdult < MiddleAged < Senior]
http://www.waitingfy.com/archives/5214
Post Views: 0
5214
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网
猜你喜欢:本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Linux/UNIX系统编程手册
Michael Kerrisk / 孙剑 许从年 董健、孙余强 郭光伟 陈舸 / 人民邮电出版社 / 2014-1 / 158
《linux/unix系统编程手册(上、下册)》是介绍linux与unix编程接口的权威著作。linux编程资深专家michael kerrisk在书中详细描述了linux/unix系统编程所涉及的系统调用和库函数,并辅之以全面而清晰的代码示例。《linux/unix系统编程手册(上、下册)》涵盖了逾500个系统调用及库函数,并给出逾200个程序示例,另含88张表格和115幅示意图。 《li......一起来看看 《Linux/UNIX系统编程手册》 这本书的介绍吧!