I have survey data that I am trying to clean up into something more useable for analysis.
I have been able to find decent guides on most of the problems, but one - tacking multiple choice questions which are passed into a single column.
What's the best practice to split it into separate columns?
I normally would do this in SQL and I would make a CASE WHEN check for each of the different options, creating as many columns as there are options.
This is an example table of what I am working with:
+----+----------------------------+
| ID | When did you attend? |
+----+----------------------------+
| 1 | Monday\nTuesday |
+----+----------------------------+
| 2 | Monday\nTuesday\nWednesday |
+----+----------------------------+
| 3 | Monday\nFriday\nSaturday |
+----+----------------------------+
This is what I think would make sense to transform into:
+----+----------------------------+--------+---------+-----------+----------+--------+----------+--------+
| ID | When did you attend? | Monday | Tuesday | Wednesday | Thursday | Friday | Saturday | Sunday |
+----+----------------------------+--------+---------+-----------+----------+--------+----------+--------+
| 1 | Monday\nTuesday | True | True | False | False | False | False | False |
+----+----------------------------+--------+---------+-----------+----------+--------+----------+--------+
| 2 | Monday\nTuesday\nWednesday | True | True | True | False | False | False | False |
+----+----------------------------+--------+---------+-----------+----------+--------+----------+--------+
| 3 | Monday\nFriday\nSaturday | True | False | False | False | True | True | False |
+----+----------------------------+--------+---------+-----------+----------+--------+----------+--------+
I have figured out so far how to pass the parts of the strings in the second column into a list using df.iloc[:,1].str.split('\n') , but I haven't figured out the next steps (even if that one is necessary).
To me it seems that would make it easier to segment the rest of the data based on what days were attended.