Issue
I have such a dataframe:
DATE | VALUE
23/07/21 01 | 20
23/07/21 02 | 10
23/07/21 03 | 15
23/07/21 04 | 200
What I want to get is new dataframe which sums up the entries of two consecutive rows of column VALUE
and keeps the entry of the second row for column DATE
.
It should look like this one:
DATE | VALUE
23/07/21 02 | 30
23/07/21 04 | 215
How can I do this?
Solution
Try:
df.groupby(np.arange(len(df))//2).agg({'DATE':'last', 'VALUE':'sum'})
Answered By - Quang Hoang
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.