I have the following dataframe.
person_id month firmid
0 1 20 12
1 1 18 10
2 1 15 13
3 2 18 13
4 2 17 11
5 2 15 13
I have a list of people with different IDs (person_id) and the month they worked in a firm in the form of a number. So person with id 1 worked in firm with id 12 during the month 20.
I want to generate a list of all the firm ids he has worked in up to date (ie the current month).
So the output should be:
person_id month firms_worked_at_up_to_current_month
0 1 20 [12,10,13]
1 1 18 [10,13]
2 1 15 [13]
3 2 18 [13,11]
4 2 17 [11,13]
5 2 15 [13]
The above is just an example. My actual file has millions of lines, so I need an efficient way to do this that doesn't involve looping.