Search code examples
pythonpandassum

Counting column contents in pandas dataframe by duplicate date


I have data like this

image

and I want to sum the column in PEMAKAIAN by same date.

I want output for example like this

image

Is that possible?


Solution

  • if you do:

    import pandas as pd
    
    df = pd.DataFrame({'day': [1, 1, 2, 2], 'PEMAKAIAN': [700.0, 720.0, 700.0, 700.0]})
    df2 = df.groupby(['day']).sum().reset_index()
    
    

    you will get the following df2 dataframe:

       day  PEMAKAIAN
    0    1     1420.0
    1    2     1400.0