samedi 6 février 2021

Repeat rows based on item count for each row and assign values for repeated rows

I have a df with the item and it is available in different rooms

  Item     Room1  Room2  Room3  Room4
  Ball      1       1     1        0
  Bat       1       1     1        1
  Wicket    1       1     1        0

Now I want to repeat the rows based on item counts on different Rooms. For example for Item - Ball there are three 1's in Room1, Room2, Room3 so need to repeat 3 rows with assigning 0 in each row only for Room1, Room2, Room3 columns, and Room4 is not considered for Item Ball and it can be 0's for all Ball item rows. There are 300 columns with different room names, for example Room1,room2,room3,room4,BlockArea1,Block2 etc.Below is the expected output

  Item     Room1  Room2  Room3  Room4
  Ball      1       1     1        0
  Ball      1       0     1        0
  Ball      1       1     0        0 
  Bat       1       1     1        1
  Bat       1       1     1        0
  Bat       1       1     0        1
  Bat       1       0     1        1
  Wicket    1       1     1        0
  Wicket    1       0     1        0
  Wicket    1       1     0        0

Any help would be appreciated




Aucun commentaire:

Enregistrer un commentaire