I have a pandas df with hundreds of rows that looks like that:
| ID | value |
|---|---|
| IDx12 | 6 |
| IDx15 | 12 |
I want to replicate these rows 2 times, increment the value column for each duplication and add a column called ratio for each one of the newly created rows.
Here are the values of ratio I want for the created rows:
- original row = 0
- first duplication = 0.25
- second duplication = 0.5
So the output should look like this:
| ID | value | ratio |
|---|---|---|
| IDx12 | 6 | 0 |
| IDx12 | 7 | 0.25 |
| IDx12 | 8 | 0.5 |
| IDx15 | 12 | 0 |
| IDx15 | 13 | 0.25 |
| IDx15 | 14 | 0.5 |
I found a very dumb way to do it by duplicating the df,incrementing value manually, adding a column with the ratio and then concatenating all the dfs.
But it's very unefficient. Do you have a smart way to do it?
thanks for your help.