0
    import pandas as pd

df=pd.read_csv('txn.csv')
print(df)

#printing the data

     Date                   debit           credit
0  01-12-2019             100.00           0.00
1  05-12-2019             200.00       500.00
2  01-12-2019             105.00       200.00
3  05-12-2019               10.00       100.00

I would like to print the aggregate data ie., sum of debit, credit as mentioned below.

Date                    debit           credit
01-12-2019             205.00        200.00
05-12-2019             210.00       600.00

Could any suggest

2 Answers2

1
df.groupby('Date').sum()

see documentation https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.groupby.html

predmod
  • 399
  • 4
  • 6
0

You need to use the groupby() function. So with your current dataframe:

aggregated = df.groupby('Date').agg({'debit':'sum','credit':'sum'})
Celius Stingher
  • 17,835
  • 6
  • 23
  • 53