I'm working with a dataframe structured as this:
| Sender | recipient | n_pass | other |
--| ------ | --------- | ------ | ------- |
0 | Emma | Lisa | 1 | other_a |
1 | Lisa | Emma | 1 | other_b |
2 | Anna | Lisa | 1 | other_c |
3 | Lisa | Anna | 1 | other_d |
4 | Emma | Jade | 1 | other_e |
5 | Lisa | Jade | 1 | other_f |
6 | Jade | Lisa | 1 | other_g |
My objective is to to merge the rows for each couple of players, regardless if they are senders or recipients, or no merge if there is no other combination.
Output should look like this:
| Player_1 | Player_2 | n_pass | other |
--| -------- | -------- | ------ | ------- |
0 | Emma | Lisa | 2 | other_a |
1 | Anna | Lisa | 2 | other_c |
2 | Emma | Jade | 1 | other_e |
3 | Lisa | Jade | 2 | other_f |
Note:
- Summing the n_pass and dropping the remaining rows is sufficient as there are other columns that don't need to be merged or changed
- I used names in this example for simplicity but the real condition will be done on unique numerical IDs for each player
I'm looking for something more efficient than my current solution using a nested loop.