I am new to Python, I have two excel files, each of them is for one month. I wanted to come and use the special code of my employees to subtract their one month's salary from their one month's salary and get the difference. I tried a lot, but I couldn't find a way. I would be grateful if you could simulate this topic on these lists for me so that I can follow your example
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"
CodePudding user response:
I guess you have the data in lists like you shown in the question and not in Pandas df. If so, I think this would work. Provided the length of employees list and salary lists are same.
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)