You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

按(Key1,Key2)分组并将多值转为限定数量新列的DataFrame处理需求

数据处理需求

原始DataFrame

Key1     Key2      Value1     Value2     FixedValue
A        A         12         32         15
A        A         40         25         15
A        A         13         12         15
A        A         80         100        15
B        A         0          1          20
B        A         0          12         20
A        B         50         50         40
B        B         7          8          30

处理要求

生成新DataFrame需满足:

  • 每个(Key1, Key2)组合仅保留一行
  • 将Value1、Value2的取值分别转为对应分组下的新列
  • FixedValue与(Key1, Key2)组合绑定,取值固定
  • 限制每个值字段(Value1、Value2)对应的新列数量为3,不足3个取值的位置用空值(或NaN等任意类型)填充

预期输出(限制新列数量为3时)

Key1     Key2      Value1_1   Value1_2   Value1_3     Value2_1   Value2_2   Value2_3     FixedValue
A        A         12         40         13           32         25         12           15
B        A         0          0                       1          12                      20
A        B         50                                 50                                 40
B        B         7                                  8                                  30

内容的提问来源于stack exchange,提问作者Adept

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.01 18:45:25