I understand how to convert my data from wide to long and vice versa; however, where I'm struggling is in keeping the relationship between 2 columns in the conversion.
Data is in a Pandas Data Frame. I can split each column independently using .split() and .expand(). Where I'm struggling is maintaining the relationship across the columns that the first value in the string list is related to the first value in the string list of the second column, and so on.
Original Data:
ID | History | Relationship |
---|---|---|
123 | 555 - Pancreatic cancer,444 - Hypertension | 1 - Mother,2 - Father |
567 | 77 - Stroke | 2 - Father |
This is what I want:
ID | History | Relationship |
---|---|---|
123 | 555 - Pancreatic cancer | 1 - Mother |
123 | 444 - Hypertension | 2 - Father |
567 | 77 - Stroke | 2 - Father |
I've tried searching multiple terms, but can't seem to find a similar question.