I have survey data in a pandas dataframe where each row is a complete survey response. It currently looks like this:
name | Question 1 | Question 2 | Question 3 |
---|---|---|---|
John | agree | disagree | neither |
Sally | disagree | neither | agree |
I want to flip it so the questions are in each row, and the results are tabulated across the rows, like this:
Question | disagree | neither | agree |
---|---|---|---|
Question 1 | 1 | 0 | 1 |
Question 2 | 1 | 1 | 0 |
Question 3 | 0 | 1 | 1 |
The responses follow a strict 5-point likert scale, so they are all consistent.
I tried to loop through a list of columns with questions and summarize using value_counts(), but I was unable to transpose it into a new df.