Create an output dataframe that consists a list of training courses to be assigned to emp based on Job Code, Work Location and a group of 3 random courses to be assigned to employee.
Please note, job code and work location need to be considered as Primary key as the same Job Code will be available across different work locations.
There are 2 dataframes, the 1st dataframe contains Emp details.
import pandas as pd
emp_data = {
'emp_id': [123456, 234567, 456789],
'job_code':[111,222,111],
'work_location':[123,234,123]
}
emp_data = pd.DataFrame(emp_data)
While 2nd dataframe contains training courses to be taken based on job code, work location and on which days the courses need to be taken.
import pandas as pd
training_matrix = {
'job_code':[111,111,111,111,111,111,222,222,222,222,222,222],
'work_location':[123,123,123,234,234,234,123,123,123,234,234,234],
'days': [1,2,3,1,2,3,1,2,3,1,2,3],
'course': ['Course1', 'Course2', 'Course3','Course4','Course5','Course6','Course7','Course8','Course9','Course10','Course1','Course2']
}
training_matrix = pd.DataFrame(training_matrix)
Output DataFrame:
import pandas as pd
output = {
'emp_id': [123456,123456,123456,234567,234567, 234567,456789,456789, 456789],
'job_code':[111,111,111,222,222,222,111,111,111],
'work_location':[123,123,123,234,234,234,123,123,123],
'days': [1,2,3,1,2,3,1,2,3],
'course': ['Course1', 'Course2', 'Course3','Course4','Course5','Course6','Course7','Course8','Course9']
}
output = pd.DataFrame(output)
output
I have tried merging but that doesn't help here, I am stuck with coming up with a logic. Any help would be greatly appreciated.
Thanks