Сначала получите манекены для 'Задачи', а затем группу
import pandas as pd
df = pd.DataFrame({ "PAT_MRN_ID" : [9641956,9641956,8227510,8165474,7860000],
"Problem" : ["Headache","Stomach-Ache","Headache","Chicken-Pox","Stomach-Ache"]
})
PAT_MRN_ID Problem
0 9641956 Headache
1 9641956 Stomach-Ache
2 8227510 Headache
3 8165474 Chicken-Pox
4 7860000 Stomach-Ache
df=pd.get_dummies(df, columns=['Problem'],prefix='',prefix_sep='')
.groupby(['PAT_MRN_ID'], as_index=False)
.max()
PAT_MRN_ID Chicken-Pox Headache Stomach-Ache
0 7860000 0 0 1
1 8165474 1 0 0
2 8227510 0 1 0
3 9641956 0 1 1