python-3.xpandaspandas-groupbydata-scrubbing

Group duplicate columns and sum the corresponding column values using pandas


I am preprocessing apache server log data. I have 3 columns ID, TIME, and BYTES. Example:

ID     TIME     BYTES

1     13:00     10

2     13:02     30

3     13:03     40

4     13:02     50

5     13:03     70

I want to achieve something like this:

ID     TIME     BYTES

1     13:00     10

2     13:02     80

3     13:03     110


Solution

  • Let's try:

    df['TIME'] = pd.to_datetime(df['TIME'])
    ax = df.groupby('TIME')['BYTES'].sum().plot()
    ax.set_xlim('13:00:00','13:03:00')
    

    Output:

    enter image description here