0

I have a DataFrame that has two columns with index set to date format (yyyy-mm-dd hh:mm:ss). What I want to achieve is to aggregate the original DataFrame into a new one, where the two columns are summed by date.

Example as follows:

Original DataFrame looks like this:

Time                    Column 1   Column 2                             
2022-11-18 12:41:00     2          1
2022-11-18 12:42:00     3          1
2022-11-19 21:43:00     3          1
2022-11-19 21:45:00     2          10

What I would like to achieve is:

Time        Column 1   Column 2                             
2022-11-18  5         2
2022-11-19  5         11

But I cannot figure out how, will appreciate any help. Many thanks!

JosephDing
  • 21
  • 2
  • Here you can find a detailed guide: https://stackoverflow.com/questions/53781634/aggregation-in-pandas and also in pandas docs: https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.groupby.html – GabrielBoehme Nov 18 '22 at 13:38

1 Answers1

0
df.set_axis(pd.to_datetime(df.index)).resample(rule='D').sum()
Panda Kim
  • 6,246
  • 2
  • 12