I have a data set like this:
dfdict = {
'a' : 'd1',
'b' : 'd1',
'c' : 'd1',
'd' : 'd2',
'e' : 'd2',
'f' : 'd3',
'g' : 'd3'
}
df = pd.DataFrame(list(dfdict.items()), columns = ['staff', 'division'])
df
staff division
0 a d1
1 b d1
2 c d1
3 d d2
4 e d2
5 f d3
6 g d3
So there are staff in different divisions. How can I assign these staff to pairs of 2, let's say to form code review groups, with these conditions:
- Each pair has a primary and a secondary reviewer.
- Each staff will serve as the primary reviewer in 1 pair and secondary in another.
- A staff can only form a pair with another staff from a different division.
- Two staff can only form a pair once. That is, if there's already a pair with
aas primary anddas secondary, then whendis primaryacan't be the secondary.
An outcome may look like this:
primary secondary
a d
b e
c g
d b
e f
f
g
I leave two last secondary values blank to describe a complication here. Up to the point where f is primary, either c or a are eligible values for secondary. However, if a is picked from the eligible pool, then the last pair is g and c, which violates the conditions as c and g is already a pair above.