0

I have a set of data in this format

| unitkey | building | floor     | unit | name       |
| 1-1-A   |    1     |     1     |   A  | Occupant 1 |
| 1-1-A   |    1     |     1     |   A  | Occupant 2 |
| 1-1-B   |    1     |     1     |   B  | Occupant 1 |
| 1-1-C   |    1     |     1     |   C  | Occupant 1 |
| 1-1-D   |    1     |     1     |   D  | Occupant 1 |
| 1-1-D   |    1     |     1     |   D  | Occupant 2 |
| 1-1-D   |    1     |     1     |   D  | Occupant 3 |

What I am trying to accomplish is to put occupant 1 and 2 on the same row. I've tried a bunch of stuff with pandas but I can't figure out how to get the ideal format. I don't really do much stuff with this, just trying to do someone a favor so any help is appreciated.

| 1-1-A   |    1     |     1     |   A  | Occupant 1 | Occupant 2 |
| 1-1-B   |    1     |     1     |   A  | Occupant 1 |            |
| 1-1-C   |    1     |     1     |   A  | Occupant 1 |            |
| 1-1-D   |    1     |     1     |   D  | Occupant 1 | Occupant 2 | Occupant 3 | 

etc.

  • `groupby+cumcount` and `pivot`, see duplicate – mozway Aug 02 '22 at 20:49
  • @mozway not helpful. Thanks. I looked through tons of examples that didn't get me where I needed which is why I posted the question. – AlarmedPigeon Aug 02 '22 at 20:54
  • Then please provide the code you tried and how it failed. This can be done with what I mentioned above. A reproducible input as DataFrame constructor would also be appreciated. – mozway Aug 02 '22 at 20:57

0 Answers0