0
点赞
收藏
分享

微信扫一扫

实验 透视表 计数 len np.count_nonzero 正确与否

雅典娜的棒槌 2023-06-02 阅读 56

实验 透视表 计数 len  np.count_nonzero 正确与否

实验 透视表 计数 len  np.count_nonzero 正确与否_错误代码

结果:

len正确 np.count_nonzero错误

结论:

除去三行干扰行(原值均为缺失值)以外:

未过账中, 有1行无业务员名称

无业务员名称中, 有1行未过账


即: 未过账且无业务员名称有1行

未过账且有业务员名称有57行

已过账且无业务员名称有57行


最终结论:

( 未过帐 或 无业务员名称 ) 且 (非缺失行)共有:

[未, :]+[已, 无] = 1+57+57 = 386-3-268

代码:

df_2.交货单过账状态.str.contains("已过").astype(str).replace({"True":"已","False":"未","nan":"无"}).to_frame().join(
    df_2.业务员名称.notna().astype(str).replace({"True":"有","False":"无"})
).pivot_table(
    index= ["交货单过账状态", "业务员名称"],
    margins= True,
    aggfunc= len
).reset_index()

# import numpy as np
df_2.交货单过账状态.str.contains("已过").astype(str).replace({"True":"已","False":"未","nan":"无"}).to_frame().join(
    df_2.业务员名称.notna().astype(str).replace({"True":"有","False":"无"})
).pivot_table(
    index= ["交货单过账状态", "业务员名称"],
    margins= True,
    aggfunc= np.count_nonzero
).reset_index()

df_2.交货单过账状态.str.contains("已过").astype(str).replace({"True":"已","False":"未","nan":"无"}).to_frame().join(
    df_2.业务员名称.notna().astype(str).replace({"True":"有","False":"无"})
).value_counts()

参考:

https://blog.51cto.com/u_16055028/6177557

https://blog.51cto.com/u_16055028/6404152

实验 透视表 计数 len  np.count_nonzero 正确与否_错误代码_02

举报

相关推荐

0 条评论