从 excel 工作表中获取员工详细信息
Get Employee Details from the excel sheeet
我有一个 excel sheet 在 A 列中仅包含“员工 ID”,如下所示。
1677
5597
5623
5618
我还有一个 excel sheet 包含 10000 多名员工的“员工详细信息”。例如:员工详细信息 excel sheet 包含包含大量员工的数据,这里是下面显示的员工 ID 的示例之一。
Empid Name Location JobTitle Email-id Department
1677 Umesh Gadag ASE abc@gmail.com Civil
这是工作代码
import pandas as pd
df1 = pd.read_excel (r'C:\Users\Kiran\Desktop\Employee id.xlsx',header=None)# excel sheet containing only ids
df2= pd.read_excel (r'C:\Users\Kiran\Desktop\Employee details.xlsx)# excel sheet containing all details of 10000+ employees
df3 = df2[df2['Empid'].isin(df1[0])]
df3.to_excel("Output1.xlsx",index=False)#Final output
代码工作正常,但我得到随机输出
Empid Name Location JobTitle Email-id Department
1677 Umesh Gadag ASE abc@gmail.com Civil
5623 Kiran Hubli SE 123@gmail.com Civil
5618 Rudra Bidar ASE xyz@gmail.com Electrical
5597 Suresh Udupi ASE ppp@gmail.com Mechanical
但是我需要按如下顺序输出,因为 Employee id 是按特定顺序排列的。基本上我在 Employee id details 中给出的顺序是什么我需要 Employee details 的顺序如下所示。
Empid Name Location JobTitle Email-id Department
1677 Umesh Gadag ASE abc@gmail.com Civil
5597 Suresh Udupi ASE ppp@gmail.com Mechanical
5623 Kiran Hubli SE 123@gmail.com Civil
5618 Rudra Bidar ASE xyz@gmail.com Electrical
这是一个解决方案:
df1 = df1.reset_index().rename(columns= {"index": "order"})
res = pd.merge(df1, df2, on = "Empid").sort_values("order").drop("order", axis=1)
输出为:
Empid Name Location JobTitle Email-id Department
0 1677 Umesh Gadag ASE abc@gmail.com Civil
1 5597 Suresh Udupi ASE ppp@gmail.com Mechanical
2 5623 Kiran Hubli SE 123@gmail.com Civil
3 5618 Rudra Bidar ASE xyz@gmail.com Electrical
我有一个 excel sheet 在 A 列中仅包含“员工 ID”,如下所示。
1677
5597
5623
5618
我还有一个 excel sheet 包含 10000 多名员工的“员工详细信息”。例如:员工详细信息 excel sheet 包含包含大量员工的数据,这里是下面显示的员工 ID 的示例之一。
Empid Name Location JobTitle Email-id Department
1677 Umesh Gadag ASE abc@gmail.com Civil
这是工作代码
import pandas as pd
df1 = pd.read_excel (r'C:\Users\Kiran\Desktop\Employee id.xlsx',header=None)# excel sheet containing only ids
df2= pd.read_excel (r'C:\Users\Kiran\Desktop\Employee details.xlsx)# excel sheet containing all details of 10000+ employees
df3 = df2[df2['Empid'].isin(df1[0])]
df3.to_excel("Output1.xlsx",index=False)#Final output
代码工作正常,但我得到随机输出
Empid Name Location JobTitle Email-id Department
1677 Umesh Gadag ASE abc@gmail.com Civil
5623 Kiran Hubli SE 123@gmail.com Civil
5618 Rudra Bidar ASE xyz@gmail.com Electrical
5597 Suresh Udupi ASE ppp@gmail.com Mechanical
但是我需要按如下顺序输出,因为 Employee id 是按特定顺序排列的。基本上我在 Employee id details 中给出的顺序是什么我需要 Employee details 的顺序如下所示。
Empid Name Location JobTitle Email-id Department
1677 Umesh Gadag ASE abc@gmail.com Civil
5597 Suresh Udupi ASE ppp@gmail.com Mechanical
5623 Kiran Hubli SE 123@gmail.com Civil
5618 Rudra Bidar ASE xyz@gmail.com Electrical
这是一个解决方案:
df1 = df1.reset_index().rename(columns= {"index": "order"})
res = pd.merge(df1, df2, on = "Empid").sort_values("order").drop("order", axis=1)
输出为:
Empid Name Location JobTitle Email-id Department
0 1677 Umesh Gadag ASE abc@gmail.com Civil
1 5597 Suresh Udupi ASE ppp@gmail.com Mechanical
2 5623 Kiran Hubli SE 123@gmail.com Civil
3 5618 Rudra Bidar ASE xyz@gmail.com Electrical