I have a dataframe like this: [2]: https://i.stack.imgur.com/D2buG.png
I want to merge the same day's readings then plus them and add a new column as day_total_read, how can i do that ?
For example indexs 2-3, 8-9, 10-11
I have a dataframe like this: [2]: https://i.stack.imgur.com/D2buG.png
I want to merge the same day's readings then plus them and add a new column as day_total_read, how can i do that ?
For example indexs 2-3, 8-9, 10-11
I'm not particularly certain how you're going to have a new column in the current table, since you'll be having an aggregate over a couple rows, and it won't be a one-to-one mapping of rows. Overall, though, you're pretty much describing a groupby operation.
Assuming df
is your dataframe, df.groupby("date").sum()
should do the trick just fine.
This'll return a new dataframe though, so if you want to merge it back into the original dataframe as a new column (like I said, won't be one-to-one, so there will be duplicates here) you'd probably wanna just column-wise append, or something like that
Here's an example of it at work