pandas 给数据打标签

import numpy as np
import pandas as pd df = pd.DataFrame(np.random.randint(0,100,100), columns=['score']) # 以所在区间作为标签。如 x=5,返回:'[0-10]'
def make_label(x, step=10):
m = x // step
return '[{}-{}]'.format(m * step, (m+1) * step) #df['level'] = df['score'].map(make_label)
df['level'] = df['score'].map(lambda x:make_label(x,step=10)) # 改变区间长度为15 res = df.groupby('level').size() print(df.head())
print(res)
上一篇:jquery 04


下一篇:sharepoint webpart