vendredi 23 octobre 2020

Assign 1 value to random sample of group where the sample size is equal to the value of another column

I want to randomly assign 1 value to the IsShade column (output) such that value 1 can be assigned only D times (see column Shading for ex 2 times or 5 times or 3 times) and have to iterate it for E times (Total column for ex 6 times or 8 times or 5 times)

There are 1 million rows of dataset and attached is sample input and image.

Input:

In[1]: 
    Sr  Series  Parallel  Shading  Total  Cell
0    0       3         2        2      6     1
1    1       3         2        2      6     2
2    2       3         2        2      6     3
3    3       3         2        2      6     4
4    4       3         2        2      6     5
5    5       3         2        2      6     6
6    6       4         2        5      8     1
7    7       4         2        5      8     2
8    8       4         2        5      8     3
9    9       4         2        5      8     4
10  10       4         2        5      8     5
11  11       4         2        5      8     6
12  12       4         2        5      8     7
13  13       4         2        5      8     8
14  14       5         1        3      5     1
15  15       5         1        3      5     2
16  16       5         1        3      5     3
17  17       5         1        3      5     4
18  18       5         1        3      5     5

If you can help me in how to achieve or python code that will be helpful. Thank you and appreciate it.

Example Expected Output:

Out[1]: 
    Sr  Series  Parallel  Shading  Total  Cell  IsShade
0    0       3         2        2      6     1        0
1    1       3         2        2      6     2        0
2    2       3         2        2      6     3        1
3    3       3         2        2      6     4        0
4    4       3         2        2      6     5        0
5    5       3         2        2      6     6        1
6    6       4         2        5      8     1        1
7    7       4         2        5      8     2        0
8    8       4         2        5      8     3        1
9    9       4         2        5      8     4        1
10  10       4         2        5      8     5        0
11  11       4         2        5      8     6        0
12  12       4         2        5      8     7        1
13  13       4         2        5      8     8        1
14  14       5         1        3      5     1        0
15  15       5         1        3      5     2        1
16  16       5         1        3      5     3        0
17  17       5         1        3      5     4        1
18  18       5         1        3      5     5        1



Aucun commentaire:

Enregistrer un commentaire