Given: I have Pandas Dataframe as shown below
| Employee_ID | Manager_ID | |:-----------:|:----------:| | E068 | E067 | | E071 | E067 | | E229 | E069 | | E248 | E144 | | E226 | E223 | | E236 | E241 | | E066 | E001 | | E067 | E001 | | E144 | E001 | | E223 | E001 | | E069 | E066 |
This problem is to identify the Head of Manager by using Employee and their Manager data.
We have an
Employee ID and their
Manager ID. Please note that Manager ID are from
Employee ID. Since each manager has one Manager above their level.
- First, we'll take all UNIQUE ID in
- Then for each ID from
Manager IDcolumn, we will look for their respective
- Then we will create a new column say
Level 1we will put manager for each
Manager IDon their respective cell.
- Similarly, we will repeat the above 3 processes again till there is no
Manager IDfor that particular ID.
- This way we can identify the
Head of Manager.
I am able to solve the problem in EXCEL.
But this approach lead me to create new column in excel for each level hierarchy. And putting the formula on first cell of that particular column and then dragging the result for each manager
But incase of big companies there would be n no. of level of hierarchy. So creating the new column in excel for each level of hierarchy would be time consuming task. Hence, I am looking for an optimal solution.
| Employee ID | Manager ID | Level 1 | Level 2 | Head of Manager | |:-----------:|:----------:|---------|---------|-----------------| | E068 | E067 | E001 | | E001 | | E071 | E067 | E001 | | E001 | | E229 | E069 | E066 | E001 | E001 | | E248 | E144 | E001 | | E001 | | E226 | E223 | E001 | | E001 | | E236 | E241 | | | E241 | | E066 | E001 | | | E001 | | E067 | E001 | | | E001 | | E144 | E001 | | | E001 | | E223 | E001 | | | E001 |
Employee IDcolumn contain UNIQUE ID while
Manager IDcontain DUPLICATES ID.
Thank you for your time and consideration.