I am used to using SQL to solve hierarchical joins but I'm wondering if it can be done in Python, maybe using Pandas. And which one is more efficient to go for?
CSV Data:
emp_id,fn,ln,mgr_id
1,Matthew,Reichek,NULL
2,John,Cottone,3
3,Chris,Winter,1
4,Sergey,Bobkov,2
5,Andrey,Botelli,2
6,Karen,Goetz,7
7,Tri,Pham,3
8,Drew,Thompson,7
9,BD,Alabi,7
10,Sreedhar,Kavali,7
I want to find the Level of each employee (Boss is Level 1 and so on):
My Recursive Code in SQL would be:
with recursive cte as
(
select employee_id, first_name, last_name, manager_id, 1 as …Run Code Online (Sandbox Code Playgroud)