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.
Update: there is at least one answer above that is far better than mine. Don't waste your time with mine.

Pandas Series module has string manipulation functions which may come in handy here. Let's start by trying:

```
from pandas import Series

response_series = df['MultipleCheckboxResponse']
split_responses = response_series.str.split('|')

```

That will split up the concatenated responses. Each element in the returned series will be a list containing each response in that row. From here we can iterate over the length of the series, and the length of each list within the series, placing each individual response in a new column in the original dataframe.

```
for i in range(0, len(split_responses)):
    for j in range(0, len(split_responses.iloc[i]+1):
        df[j+4][i] = split_responses.iloc[i][j]

```