I have a data frame like below
I would like to convert the data frame as below. All the codes are in code column are categorical variable, each of the categorical variable need to come as a separate column and need one-hot encoding. challenge here is unit of encoding need to be at member level. For example, Patient1 summary shows from the picture below, A123 coded as 1, B123 coded as 1, C123 coded as 1 and D123 coded as 0 and score is an average of the scores for patient 1.