[英]How to understand the difference between 2 lists, provided that the names in the other 2 lists are equal
我是 Python 的新手,我有兩個 excel 文件,每個文件都是一個月的。 我想來用我員工的特殊代碼,從他們一個月的工資中減去他們一個月的工資,然后得到差額。 我嘗試了很多,但我找不到方法。 如果您能為我在這些列表中模擬這個主題,我將不勝感激,以便我可以按照您的示例進行操作
salary_month_1 = [232, 432]
employee_list_month_1 = ['elly', 'john']
employee_list_month_2 = ['elly', 'john']
salary_month_2 = [540, 655]
# output I need : "elly (540 - 232) = 308", "john (655 - 432) = 223"
我猜您的列表中有問題中顯示的數據,而不是 Pandas df 中的數據。 如果是這樣,我認為這會奏效。 前提是員工名單和工資名單的長度相同。
salary_month_1 = [232, 432]
employee_list_month_1 = ['elly', 'john']
employee_list_month_2 = ['elly', 'john']
salary_month_2 = [540, 655]
emp_list = set(employee_list_month_1) & set(employee_list_month_2)
emp_salary = {}
for index, emp in enumerate(emp_list):
salary1 = salary_month_1[index]
salary2 = salary_month_2[index]
emp_salary[emp] = salary2 - salary1
print(emp_salary)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.