Let's take a look at a simple HR dataframe as an example:
| Name | Year | Department | Salary | New column: hit100after |
|---|---|---|---|---|
| John | 2018 | R&D | 80 | 0 |
| Marie | 2018 | Legal | 90 | 0 |
| Jill | 2018 | Legal | 100 | 0 |
| John | 2019 | R&D | 85 | 0 |
| Marie | 2019 | Legal | 95 | 0 |
| Jill | 2019 | Legal | 105 | 1 |
| John | 2020 | R&D | 90 | 0 |
| Marie | 2020 | Legal | 100 | 2 |
| Jill | 2020 | Legal | 110 | 2 |
Question: How much time (in years) did it take for any data set to achieve a salary >= 100 AFTER the first person in the same department hit that number? (see new column 'hit100after')
I am actually struggeling with the implementation. My steps would be to group by department and find the first occurrence of salary >= 100 and mark that year with a new boolean type or a second dataframe. Then I would calculate the differences between >= 100 of an individual and the first occurrence in its department.
Any idea how to code that for a large dataframe?