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)

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-01-21
  • 2021-05-09
  • 2021-10-02
  • 2021-09-15
猜你喜欢
  • 2022-03-09
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-30
  • 2022-02-28
相关资源
相似解决方案