0

I saw this code combine rows and add up value in dataframe,

but I want to add the values in cells for the same day, i.e. add all data for a day. how do I modify the code to achieve this?

  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Jul 27 '22 at 14:56

1 Answers1

0

Check below code:

import pandas as pd 
df = pd.DataFrame({'Price':[10000,10000,10000,10000,10000,10000],
                   'Time':['2012.05','2012.05','2012.05','2012.06','2012.06','2012.07'],
                   'Type':['Q','T','Q','T','T','Q'],
                   'Volume':[10,20,10,20,30,10]
                   })

df.assign(daily_volume = df.groupby('Time')['Volume'].transform('sum'))

Output:

enter image description here

Abhishek
  • 1,585
  • 2
  • 12
  • 15
  • thank you. let us assume the type column is not there and I want to add the values in 'Volume' and 'daily_volume' for each month i.e for 2012.05 volume=10+20+10 and daily_volume= 40+40+40. instead of T used in the main post (link in the main question – Oladipo Mumin Jul 27 '22 at 15:02
  • It would be helpful if you can provide dummy data & complete expected output – Abhishek Jul 27 '22 at 15:04