Unpivot survey answers without inventing scores · Python (pandas)
Task: the rules
Input survey(respondent, q1, q2, q3) — text. respondent is unique. Each answer is a whole number 1–5 or missing. Rules Reshape to one row per respondent and question: question is the column name (q1, q2 or q3), score is the answer as a whole number. An unanswered question produces no row. It is not a score of 0 and it is not an error. Output (row order does not matter) clean(respondent text, question text, score int64)
Tab inserts spaces. Press Escape, then Tab, to move focus out of the editor.
| # | respondentstring | q1string | q2string | q3string |
|---|---|---|---|---|
| 1 | r344 | 2 | 1 | missing |
| 2 | r390 | missing | missing | missing |
| 3 | r342 | 5 | 3 | missing |
| 4 | r340 | missing | 1 | 2 |
| 5 | r341 | 5 | missing | 1 |
| 6 | r343 | 3 | 2 | 4 |
Run preview · in your browser, not a grade
Loading the preview runtime…
Check answer · graded on an isolated server, including hidden datasets
Your code runs in a locked-down machine with no network, on the visible data and on hidden datasets that follow the same rules.
Learn from this exercise
A worked solution becomes available after your first check or once you've used every hint.