I have such a dataframe:
JavaScript
x
7
1
ds y
2
2018-07-25 22:00:00 1
3
2018-07-25 23:00:00 2
4
2018-07-26 00:00:00 3
5
2018-07-26 01:00:00 4
6
2018-07-26 02:00:00 5
7
What I want to get is a new dataframe which looks like this
JavaScript
1
4
1
ds y
2
2018-07-25 3
3
2018-07-26 12
4
I want to get a new dataframe df1 where all the entries of one day are summed up in y
and I only want to keep one column of this day without a timestamp.
What I did so far is this:
JavaScript
1
2
1
df1 = df.groupby(df.index.date).transform(lambda x: x[:24].sum())
2
24 because I have 24 entries every day (for every hour). I get the correct sum for every day but I also get 24 rows for every day together with the existing timestamps. How can I achieve what I want?
Advertisement
Answer
If need sum all values per days then filtering first 24 rows is not necessary:
JavaScript
1
2
1
df1 = df.groupby(df.index.date)['y'].sum().reset_index()
2