Say I have a Pandas Dataframe below:
| ID | value |
|---|---|
| 0 | 1 |
| 1 | 2 |
| 2 | 1.2 |
| 3 | 1.6 |
| 4 | 1.5 |
| 5 | 1.4 |
| 6 | 1.1 |
I would like to group the Values within 20% margin of the first element of the group.
| ID | value | group |
|---|---|---|
| 0 | 1 | 0 |
| 2 | 1.2 | 0 |
| 6 | 1.1 | 0 |
| 1 | 2 | 1 |
| 3 | 1.6 | 1 |
| 4 | 1.5 | 2 |
| 5 | 1.4 | 2 |
What is the best way to do this?