看来您正在使用Pandas库。它们包括执行此 *** 作的功能:http : //pandas.pydata.org/pandas-
docs/version/0.16.0/genic/pandas.cut.html
这是我的尝试:
import pandas as pdages = pd.Dataframe([81, 42, 18, 55, 23, 35], columns=['age'])bins = [18, 30, 40, 50, 60, 70, 120]labels = ['18-29', '30-39', '40-49', '50-59', '60-69', '70+']ages['agerange'] = pd.cut(ages.age, bins, labels = labels,include_lowest = True)print(ages) age agerange0 81 70+1 42 40-492 18 18-293 55 50-594 23 18-295 35 30-39
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)