0

I have a dataset which contains several rows with the same ID and different values, such as for example :

id surface other_columns
1  40       ...
1  20       ...
1  50       ...
2  30       ...
3  25       ...

My goal would be to be able to add surface according to the id while keeping the other columns such as:

id surface other_columns
1  110      ...
2  30       ...
3  25       ...

I tried using groupby(), but it logically discarded the other columns which is problematic.

My second idea was to get the sum of surface according to the id for each value of the column surface; then drop the duplicates in order to have one instance remaining of each id with the correct amount of surface.

The problem is that I don't know how to do this, or even if it's a viable idea or if there are better options.

not_speshal
  • 22,093
  • 2
  • 15
  • 30
Frejac
  • 3
  • 3
  • how do you want to keep the other columns? Can you give an example? – mozway May 11 '22 at 15:35
  • check if [this](https://stackoverflow.com/questions/68792897/how-can-repetitive-rows-of-data-be-collected-in-a-single-row-in-pandas) is what you want – mozway May 11 '22 at 15:36

0 Answers0