基于其他列对列的值求和并保存

2024-05-06 08:46:41 发布

您现在位置:Python中文网/ 问答频道 /正文

df1=

A        B
61880    7
62646    8
62651    9
62656    10
62783    11
61880    3
62646    2

我想做data.groupby('A')['B'].sum(),但是要根据“a”的值将“B”的结果保存为新列“B\u updated”

data.groupby('A')['B'].sum()之后,我的输出是:

A        B
61880    10
62646    10
...

很好,但我不能做进一步的手术。因此,我想保存“B”和“A”。因为我的下一个操作是Math operations of column based on same values of other column pandas


Tags: ofdataoncolumnmathbasedoperations手术