I have a table as given below.
I am trying to rearrange the table in a certain manner so that I have the unique values of the column 'Metric Category' as separate columns and the corresponding values from the 'Response' column as values. Though I have been able to solve till here with the following code
df2.set_index([df2.groupby(['Metric_Category'])['Metric_Category'].cumcount(), 'Metric_Category'])['Response'].unstack()
However, I am unable to figure out how to add the corresponding 'Participant' name alongside the responses as follows.
CodePudding user response:
Add column Participant
to MultiIndex
:
df2.set_index(['Participant',df2.groupby(['Metric_Category'])['Metric_Category'].cumcount(), 'Metric_Category'])['Response'].unstack()