-1

df1 =

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

I want to do data.groupby('A')['B'].sum() but in the way to save the result of "B" as a new column "B_updated" based on values of "A"

After data.groupby('A')['B'].sum() my output is:

A        B
61880    10
62646    10
...

It is good, but I can not perform further operations. Thus, I want to save "B" wrt "A". Because my next operation will be Math operations of column based on same values of other column pandas

1 Answers1

0

Try this:

x_df = df.groupby('A').size().reset_index(name='B_updated')
print(x_df)
Chirag
  • 259
  • 1
  • 8