'How to create multiple subsets of df based on main column/category?

Let's suppose I have a very large df of these columns with sub-columns. Row 0 is the main column(it has many duplicates, Row 1 is the sub-column inside the column. I want to break each column into its' own df of sub-columns.

The only way that I know how to do this is by taking it apart one by one and joining them; however, there are close to 6,000 columns. Also, Patient ID needs to be the "Unique Identifier" in each df.

0 Benefits Benefits id Care Care
1 Medicare TYPE Med Type Patient ID Type of care position of care
2 Medicare A Medicare B Patient/51792geyfg Skilled primary
3 Not enrolled UNKNOWN Patient/rgyrebhrbv MD secondary

Desired Output: 1st df

Benefit's df

0 Medicare TYPE Med Type
1 Medicare A Medicare B
2 Medicare A Medicare B
3 Not enrolled UNKNOWN

2nd df ID df

0 Patient ID
1 Medicare A
2 Not enrolled

3rd df Care df

0 Type of care position of care
1 Skilled primary
2 MD secondary


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source