One option is with [pivot_longer](https://pyjanitor-devs.github.io/pyjanitor/api/functions/#janitor.functions.pivot.pivot_longer) from [pyjanitor](https://pyjanitor-devs.github.io/pyjanitor/) - in this case we use the special placeholder `.value` to identify the parts of the column that we want to remain as headers, while the rest get collated into a new column :
```py
# pip install pyjanitor
import pandas as pd
import janitor
(df
.pivot_longer(
index = [slice('Start', 'Type'), slice('Re', 'Set3')],
names_to = ("Range", ".value"),
names_sep = " ")
)
Start Date End Area Final Type Re Set Set2 Set3 Range Stat Stat1
0 8/1/2013 9/1/2013 10/1/2013 NY 3/1/2023 CC 0 0 0 0 Middle 226 0
1 8/1/2013 9/1/2013 10/1/2013 CA 3/1/2023 AA 0 0 0 0 Middle 130 0
2 8/1/2013 9/1/2013 10/1/2013 NY 3/1/2023 CC 0 0 0 0 Low 20 0
3 8/1/2013 9/1/2013 10/1/2013 CA 3/1/2023 AA 0 0 0 0 Low 50 0
4 8/1/2013 9/1/2013 10/1/2013 NY 3/1/2023 CC 0 0 0 0 High 10 0
5 8/1/2013 9/1/2013 10/1/2013 CA 3/1/2023 AA 0 0 0 0 High 0 0
```
One option is with [pivot_longer](https://pyjanitor-devs.github.io/pyjanitor/api/functions/#janitor.functions.pivot.pivot_longer) from [pyjanitor](https://pyjanitor-devs.github.io/pyjanitor/) - in this case we use the special placeholder `.value` to identify the parts of the column that we want to remain as headers, while the rest get collated into a new column :
```py
# pip install pyjanitor
import pandas as pd
import janitor
(df
.pivot_longer(
index = slice('Start', 'Type'),
names_to = ("Range", ".value"),
names_sep = " ")
)
Start Date End Area Final Type Range Stat Stat1
0 8/1/2013 9/1/2013 10/1/2013 NY 3/1/2023 CC Middle 226 0
1 8/1/2013 9/1/2013 10/1/2013 CA 3/1/2023 AA Middle 130 0
2 8/1/2013 9/1/2013 10/1/2013 NY 3/1/2023 CC Low 20 0
3 8/1/2013 9/1/2013 10/1/2013 CA 3/1/2023 AA Low 50 0
4 8/1/2013 9/1/2013 10/1/2013 NY 3/1/2023 CC High 10 0
5 8/1/2013 9/1/2013 10/1/2013 CA 3/1/2023 AA High 0 0
```