'How to crate a Hybrid Work Model roster simulation

My office is currently manually creating employee rosters for our Hybrid work model.

A roster is a weekly or biweekly calendar, stating which all employees should come to office on which day of the week.

Can we automate the process in Python/Pandas?


Rules for creating a 2 week roster:

  • in a week (5 working days)
    • maximum days in office: 3 days
    • minimum days in office: 2 days
  • in 2 weeks (10 working days)
    • number of days in office: 5 days
  • coinciding days
    • atleast 1 day in the week, the employee (Id column) should be on office on the day when his/her manager (ManagerId column) is also in office
  • Roster should be randomly generated and employees should get reporting days randomly assigned, in order to avoid repetitive pattern reoccurring

E.g. for team mappings:


EmpId Name Team ManagerId
0 Z Z 90
1 Abc A 0
2 Ade A 1
3 Afg A 1
4 Bmn B 0
5 Bop B 4
6 Bqr B 4
7 Bst B 4
8 Ctu C 0
9 Cvw C 8
10 Cxy C 8
11 Djk D 0
12 Dlm D 11
13 Dno D 11
14 Dpq D 11

Results in a roster that looks like (can be any format/shape, below is only for visual representation):


Mon1 Tue1 Wed1 Thu1 Fri1 Mon2 Tue2 Wed2 Thu2 Fri2
Z Z Afg Ctu Ctu Abc Z Z Z Djk
Abc Abc Cvw Abc Ade Ctu Ctu Ctu Cvw
Ade Ade Cxy Cvw Ade Afg Cvw Cvw Bmn Cxy
Afg Afg Bop Cxy Dlm Cxy Cxy Dlm Dlm
Dlm Bmn Bqr Bmn Dno Abc Dno Dno
Dno Bop Bst Bop Dpq Afg Ade Dpq Dpq
Dpq Bqr Dlm Bqr Bmn Bmn
Bst Dno Bst Bop Bop
Dpq Bqr Bqr
Bst Bst

If you want to play around, the dataset:

import pandas as pd
import numpy as np
EmpId =  np.arange(15)
Name = ['Z', 'Abc', 'Ade', 'Afg', 'Bmn', 'Bop', 'Bqr', 'BSt', 'Ctu', 'Cvw', 'Cxy', 'Djk', 'Dlm', 'Dno', 'Dpq']
Team = ['Z', 'A', 'A', 'A', 'B', 'B', 'B', 'B', 'C', 'C', 'C', 'D', 'D', 'D', 'D'] 
ManagerId = [90, 0, 1, 1, 0, 4, 4, 4, 0, 8, 8, 0, 11, 11, 11]

team_mapping_df = pd.DataFrame(zip(EmpId , Name, Team, ManagerId), columns = ['EmpId ', 'Name', 'Team', 'ManagerId'])
team_mapping_df


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source