小编Kas*_*ash的帖子

Recursive Hierarchical Join in Python DataFrame

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)

python dataframe pandas

4
推荐指数
1
解决办法
3532
查看次数

标签 统计

dataframe ×1

pandas ×1

python ×1