根据Python中的条件在列中添加值

问题描述 投票:1回答:2
Source_No  Parent   Type    Amt
123         123     Tail    100
456         123     Coll    100
789         123     Coll    100

我想让代码在新列'Tot_Amt'中创建一个新列,该列将添加所有Source_No的Amt,其中Parent = Source_No并用于其他

预期输出。

Source No  Parent   Type    Amt     Tot_Amt
123         123     Parent   100     200
456         123     Child    100      0
789         123     Child    100      0
python pandas
2个回答
0
投票

您在这里:


0
投票

执行此操作的一种方法是根据您的Parent = Source_No约束进行分组,聚合,然后合并回去

© www.soinside.com 2019 - 2024. All rights reserved.