Is there a better way to create a listing of employees that belong to a single leaders' organization when I only have a listing of employees and their managers?
My current approach is to find in FULL (dataframe with all employees and their managers) the employees who report to that executive (TEMP1), append TEMP1 to a running list (SMITH_STAFF), then iterate over TEMP1 to find their direct reports in FULL (saved to TEMP2), save TEMP2 to SMITH_STAFF, etc.
My approach works, but it is quite kooky. There has to be a better way, but all my searches and trying for loops, etc. did not work. I can't find a more elegant way.
The FULL dataframe contains 'Email Address' and 'Manager Email Address' for all employees. Example:
Email Address Mgr Email Address employee1 johnsmith employee2 employee1 employee3 employee2 employee4 tomhamks
SMITH_STAFF = pd.DataFrame()
TEMP1 = FULL.loc[FULL['Mgr Email Address']=="johnsmith@company.com"]
SMITH_STAFF = SMITH_STAFF.append(TEMP1)
TEMP2 = pd.DataFrame()
for index, row in TEMP1.iterrows():
TEMP2 = TEMP2.append(FULL.loc[FULL['Mgr Email Address']==row["Email
Address"]])
SMITH_STAFF = SMITH_STAFF.append(TEMP2)
TEMP3 = pd.DataFrame()
for index, row in TEMP2.iterrows():
TEMP3 = TEMP3.append(FULL.loc[FULL['Mgr Email Address']==row["Email
Address"]])
SMITH_STAFF = SMITH_STAFF.append(TEMP3)
I expect the smith staff file to contain the employee and manager email addresses for all employees that ultimately report up to JohnSmith. In this example, that would be employee1, employee2, and employee3