I have a pandas dataframe which looks like this:
df = pd.DataFrame({
'job': ['football','football', 'football', 'basketball', 'basketball', 'basketball', 'hokey', 'hokey', 'hokey', 'football','football', 'football', 'basketball', 'basketball', 'basketball', 'hokey', 'hokey', 'hokey'],
'team': [4.0,5.0,9.0,2.0,3.0,6.0,1.0,7.0,8.0, 4.0,5.0,9.0,2.0,3.0,6.0,1.0,7.0,8.0],
'cluster': [0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1]
})
Each cluster contains 9 teams. Each cluster has 3 teams of each type of sport football, basketball and hokey. I want to apply a shift-function to each cluster, so that the order of teams chance in a very specific way (I tried to highlight it with color):
How can I do this transformation (shift rows in a way shown above) for a much larger dataframe?

