Python3 Pandas 统计问题

2018-12-20 18:25:40 +08:00
 Kakarrot

有什么办法可以确保加上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
1440 次点击
所在节点    Python
2 条回复
neosfung
2018-12-20 18:59:38 +08:00
labels 不是应该是 list 么?
imn1
2018-12-20 19:02:36 +08:00
好像跟统计没什么关系

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/519490

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX