Question: I have a DataFrame with some survey results; each column is the response to a question. However, for a question that allowed multiple (<10) answers from checked boxes, the column has concatenated those answers with the format "Response 1 Checked | Response 4 Checked | Response 6 Checked ....", so I can't just split the column based on a predefined order, as it doesn't say when something was not checked.

```
ID     NormalResponse    MultipleCheckboxResponse
1      Answer3           Response 3
2      Answer1           Response 1| Response 7
3      Answer2           Response 2| Response 4| Response 7
4      Answer2           Response 2 | Response 3

```

How do I split these reasons out as new columns, preferably just with a boolean marker or 1/0 in the cell to determine if it was marked.

I'd like to see

```
ID     NormalResponse    Response1    Response2   Response3     Response4...
1      Answer3           0            0            1            0
2      Answer1           1            0            0            0
3      Answer2           0            1            0            1
4      Answer2           0            1            1            0

```

Answer: 
Assume you have a dataframe like this

```
df
#  ID NormalResponse       MultipleCheckboxResponse
#0  1        Answer3                      Response3
#1  2        Answer1            Response1|Response7
#2  3        Answer2  Response2|Response4|Response7
#3  4        Answer2            Response2|Response3

```

You can do the following

```
responses  = df.MultipleCheckboxResponse.unique() # find unique responses in each column
u_response = set( [ x for sublist in responses for x in sublist.split('|') ] ) # find total unique responses in dataframe (maps the 2d list responses to a 1d list)
#{'Response1', 'Response2', 'Response3', 'Response4', 'Response7'}

```

(Note that the set function returns only unique values). At this point you can iterate over the unique responses. For each response variable you should

1. create a data column matching response variable name
2. initializing each value for 0
3. Check each row if the column name (response variable) is in the `MultiCheckboxResponse` column. If it is, set the row val to 1.

this is what the loop should look like.

```
for col in u_response:
    df[col] = 0 # initialize the col
    df.loc[df.MultipleCheckboxResponse.str.contains(col), col] = 1 # adjust as necessary

df
#  ID NormalResponse       MultipleCheckboxResponse  Response7  Response4  \
#0  1        Answer3                      Response3          0          0   
#1  2        Answer1            Response1|Response7          1          0   
#2  3        Answer2  Response2|Response4|Response7          1          1   
#3  4        Answer2            Response2|Response3          0          0   

#   Response2  Response3  Response1  
#0          0          1          0  
#1          0          0          1  
#2          1          0          0  
#3          1          1          0 

```

See [here](http://pandas.pydata.org/pandas-docs/stable/text.html) for more ideas on working with text data.

update
------

you seem to have extraneous white spaces, so you might want to change the `u_response` line of code to

```
u_response = set( [ x.strip() for sublist in responses for x in sublist.split('|') ]

```

where we added the `strip` method. This way your column titles do not have white spaces.
You can use [`get_dummies`](http://pandas.pydata.org/pandas-docs/stable/generated/pandas.get_dummies.html), after some string manipulation to remove the spaces around the vertical bars `|`:

```
>>> resp = df.MultipleCheckboxResponse.str.replace("[\s]*\|[\s]*", "|")
>>> dummies = resp.str.get_dummies(sep="|")
>>> df.iloc[:,:2].join(dummies)
   ID NormalResponse  Response 1  Response 2  Response 3  Response 4  Response 7
0   1        Answer3           0           0           1           0           0
1   2        Answer1           1           0           0           0           1
2   3        Answer2           0           1           0           1           1
3   4        Answer2           0           1           1           0           0

```

Note though that this will only generate columns for the responses which were ever actually seen. If you want a `response6` column even though no one ever reported response6, then you'll need to add those in a loop yourself.