Problem: I have a data frame that I need to modify based on the values of particular column. If value of any column value is greater than that of maximum allowed then a new row will be created based upon distribution into equally sized bins (taking integer division between data value and max allowed value)
Table and Explanation:
Original:
| Index | Data 1 | Data 2 | Max. Allowed |
|---|---|---|---|
| 1 | 1 | 2 | 3 |
| 2 | 10 | 5 | 8 |
| 3 | 7 | 12 | 5 |
Required:
Index Values in brackets refers to the original index value
| Index | Data 1 | Data 2 | Max. Allowed |
|---|---|---|---|
| 1 (1) | 1 | 2 | 3 |
| 2 (2) | 8 | 5 | 8 |
| 3 | 2 | 0 | 8 |
| 4 (3) | 5 | 5 | 5 |
| 5 | 2 | 5 | 5 |
| 6 | 0 | 2 | 5 |
Since original index = 2, had Data1 = 10 which is greater than max allowed = 8. This row has been broken into two rows as shown in the above table.
Attempt: I was able to find those columns which had value greater than max allowed and number of rows to be inserted. But I had a confusion wether that approach would work if both columns would have value greater than the max allowed value (as in case of index = 3). The values indicate how many more rows to be inserted for each index value for particular column.
| Index | Data 1 | Data 2 |
|---|---|---|
| 1 | 0 | 0 |
| 2 | 1 | 0 |
| 3 | 1 | 2 |