python - pivot_table 返回长度错误的表
问题描述
我对 pandas(python)的 pivot_table 函数的输出有疑问。我试图在 ProductName 上旋转一个表,将 CustomerId 设置为索引并聚合 Quantities,以获得每个客户和类别的总销售额。我使用的代码如下:
products_sum = pd.pivot_table(sales_per_customer,
values='Quantity',
index='CustomerId',
columns='ProductName',
aggfunc = "sum").reset_index()
products_sum
问题是,虽然我有 107157 个唯一的 CustomerId,但 pivot_table 函数返回一个包含 106934 行的数据框(缺少 223 个 CustomerId)。我已经检查了 CustomerIds 上没有空值。
先感谢您
解决方案
推荐阅读
- vbscript - 用于修改 Windows 7 库的 VBS 脚本在提升时不起作用
- ios - AuthDataResult 类型的值没有成员 providerID
- python - 在 python 中使用正则表达式/替换替换文本中的字母数字
- sql-server - 将列名映射到行
- c - 我的 C 程序只读取第一行。我试图让它读取文本文件的所有内容
- c# - 无法让机器人直接向我的整个服务器发送消息
- django - 根据外键过滤
- react-native - 使用 react-native 进行反应导航:如果是组件的一部分,则不会呈现 DrawerIcon
- sql-server - Asp.net 身份:为什么索引在 GUID (nvarchar) 上?使用 int 有什么好处/缺点?
- java - 如何解决 spring-kafka 中的 MessageConversionException?