How to separate one column in dataframe into many? [python, pandas]

What I have in mind is converting a dataframe like this:

Letters
A; B; C
B; C
A; B; C
A
B

Into this:

A B C
1 1 1
0 1 1
1 1 1
1 0 0
0 1 0

Any ideas on how to do that? I have been able to split the column based on “; “, but I have no idea how to categorize them.

Thanks!

Answer

Try with get_dummies

out = df.Letters.str.get_dummies('; ')
   A  B  C
0  1  1  1
1  0  1  1
2  1  1  1
3  1  0  0
4  0  1  0