Helenr
我的猜测是你想要这个:df = pd.DataFrame({'A': [1,1,2,2,3,3], 'B': [2,2,2,3,3,3], 'TotalAmount': [10,20,30,40,50,60]})df['NewColumn'] = df.groupby(['A', 'B'])['TotalAmount'].transform('sum')df# A B TotalAmount NewColumn#0 1 2 10 30#1 1 2 20 30#2 2 2 30 30#3 2 3 40 40#4 3 3 50 110#5 3 3 60 110