
有什么办法可以确保加上labels参数后,输出的结果是准确的?
result = pd.DataFrame(recharge_user).groupby( pd.cut( np.array(recharge_user), bins=[0, 10, 50, 100, 500, 1000, 3000, 5000, 10000, np.inf], # labels={ # '10 元以下人数:', # '10-50 元人数:', # '50-100 元人数:', # '100-500 元人数:', # '500-1000 元人数:', # '1000-3000 元人数:', # '3000-5000 元人数:', # '5000-10000 元人数:', # '10000 元以上人数:' # } ) ).count() print(result) 打印结果 1:正确!
(0.0, 10.0] 1120 (10.0, 50.0] 661 (50.0, 100.0] 220 (100.0, 500.0] 406 (500.0, 1000.0] 108 (1000.0, 3000.0] 92 (3000.0, 5000.0] 15 (5000.0, 10000.0] 5 (10000.0, inf] 1 打印结果 2:错误!
10 元以下人数: 1120 50-100 元人数: 661 1000-3000 元人数: 220 100-500 元人数: 406 10000 元以上人数: 108 500-1000 元人数: 92 3000-5000 元人数: 15 10-50 元人数: 5 5000-10000 元人数: 1