import numpy as np
import pandas as pd
df = pd.DataFrame(np.random.randint(0,100,100), columns=['score'])
def make_label(x, step=10):
m = x // step
return '[{}-{}]'.format(m * step, (m+1) * step)
df['level'] = df['score'].map(lambda x:make_label(x,step=10))
res = df.groupby('level').size()
print(df.head())
print(res)
本文转自罗兵博客园博客,原文链接:http://www.cnblogs.com/hhh5460/p/5817452.html,如需转载请自行联系原作者