lundi 20 novembre 2023

rotation lists based on columns out of pandas dataframe with restrictions

I want to create a random tool for a station rotation for the names: I have a given Dataframe with the following shape:

data = {'Name': ['Tom', 'Mike', 'Carl', 'Juli', 'Tina', 'Wendy'],
        'station1': [0, 1, 1, 1, 0, 0],
        'station2': [1, 1, 1, 1, 1, 0], 
        'station3': [1, 1, 1, 1, 1, 1],
        'station4': [1, 1, 1, 1, 1, 1],
        'station5': [0, 1, 0, 0, 1, 0],
        'station6': [1, 1, 0, 1, 1, 0]}

4x rotation = 4 postions in list

Restrictions for rotations: no double station at for e.g. 1st position in each list no station following each other, and if possible Wendy can only do 2 stations, so a double change is minimum. (see at expeced result below)

I think working with list is the best way, but not sure if 4-D array is also a choice.

my prgress so far:

  1. replace 1 with 'station_'
  2. swapaxes()
  3. creat lists for each name
  4. delete 'nan's in name lists
  5. set name as list name and delete name from list (so lists have different len)
  6. ... no idea, maybe sort by length?
  7. ... maybe pic and check by column/rows?

List should be like

Wendy = ['station4','station3','station4','station3']
Mike = ['station1','station2','station5','station6']

...

Tom = ['station2','station4','station6','station2']

I know is tricky and difficult, but i have no clue how to coninue




Aucun commentaire:

Enregistrer un commentaire