I have df1 which has three columns (loadgroup, cartons, blocks) like this
loadgroup | cartons | blocks | cartonsPercent | blocksPercent |
---|---|---|---|---|
1 | 2269 | 14 | 26% | 21% |
2 | 1168 | 13 | 13% | 19% |
3 | 937 | 8 | 11% | 12% |
4 | 2753 | 24 | 31% | 35% |
5 | 1686 | 9 | 19% | 13% |
total(sum of column) | 8813 | 68 | 100% | 100% |
The interpretation is like this: out of df1 26% cartons which is also 21% of blocks are assigned to loadgroup 1, etc. we can assume blocks are 1 to 68, cartons are 1 to 8813. I also have df2 which also has cartons and blocks columns. but does not have loadgroup. My goal is to assign loadgroup (1-5 as well) to df2 (100 blocks 29608 cartons in total), but keep the proportions, for example, for df2, 26% cartons 21% blocks assign loadgroup 1, 13% cartons 19% blocks assign loadgroup 2, etc. df2 is like this:
block | cartons |
---|---|
0 | 533 |
1 | 257 |
2 | 96 |
3 | 104 |
4 | 130 |
5 | 71 |
6 | 68 |
7 | 87 |
8 | 99 |
9 | 51 |
10 | 291 |
11 | 119 |
12 | 274 |
13 | 316 |
14 | 87 |
15 | 149 |
16 | 120 |
17 | 222 |
18 | 100 |
19 | 148 |
20 | 192 |
21 | 188 |
22 | 293 |
23 | 120 |
24 | 224 |
25 | 449 |
26 | 385 |
27 | 395 |
28 | 418 |
29 | 423 |
30 | 244 |
31 | 327 |
32 | 337 |
33 | 249 |
34 | 528 |
35 | 528 |
36 | 494 |
37 | 540 |
38 | 368 |
39 | 533 |
40 | 614 |
41 | 462 |
42 | 350 |
43 | 618 |
44 | 463 |
45 | 552 |
46 | 397 |
47 | 401 |
48 | 397 |
49 | 365 |
50 | 475 |
51 | 379 |
52 | 541 |
53 | 488 |
54 | 383 |
55 | 354 |
56 | 760 |
57 | 327 |
58 | 211 |
59 | 356 |
60 | 552 |
61 | 401 |
62 | 320 |
63 | 368 |
64 | 311 |
65 | 421 |
66 | 458 |
67 | 278 |
68 | 504 |
69 | 385 |
70 | 242 |
71 | 413 |
72 | 246 |
73 | 465 |
74 | 386 |
75 | 231 |
76 | 154 |
77 | 294 |
78 | 275 |
79 | 169 |
80 | 398 |
81 | 227 |
82 | 273 |
83 | 319 |
84 | 177 |
85 | 272 |
86 | 204 |
87 | 139 |
88 | 187 |
89 | 263 |
90 | 90 |
91 | 134 |
92 | 67 |
93 | 115 |
94 | 45 |
95 | 65 |
96 | 40 |
97 | 108 |
98 | 60 |
99 | 102 |
total 100 blocks | 29608 cartons |
I want to add loadgroup column to df2, try to keep those proportions as close as possible. How to do it please? Thank you very much for the help.