Is it possible to transform Table 1 to table 2, where a new multi-index table is created so that a specific 'class_section' grouping has its own index order? Is using group by required? or is there another way I can do this by split.apply.combine technique?
Thanks in advance.
Table 1
| name | movie_watch_count | class_section | |
|---|---|---|---|
| 0 | Morris | 2 | 2 |
| 1 | Gertie | 3 | 1 |
| 2 | Kristal | 3 | 1 |
| 3 | Roslyn | 4 | 2 |
| 4 | Tari | 7 | 2 |
| 5 | Dewayne | 1 | 1 |
| 6 | Edward | 6 | 2 |
| 7 | Frank | 0 | 2 |
Table 2
| global_index | group_index | name | movie_watch_count | class_section | |
|---|---|---|---|---|---|
| 0 | 1 | 0 | Gertie | 3 | 1 |
| 1 | 2 | 1 | Kristal | 3 | 1 |
| 2 | 5 | 2 | Dewayne | 1 | 1 |
| 3 | 0 | 0 | Morris | 2 | 2 |
| 4 | 3 | 1 | Roslyn | 4 | 2 |
| 5 | 4 | 2 | Tari | 7 | 2 |
| 6 | 6 | 3 | Edward | 6 | 2 |
| 7 | 7 | 4 | Frank | 0 | 2 |