df = pd.DataFrame(["c", "b", "a p", NaN, "ap"])
df[0].str.get_dummies(' ')
The above code prints something like this.
a p b c ap
0 0 0 0 1 0
1 0 0 1 0 0
2 1 1 0 0 0
3 0 0 0 0 0
4 0 0 0 0 1
The required output is the following:
a p b c
0 0 0 0 1
1 0 0 1 0
2 1 1 0 0
3 0 0 0 0
4 1 1 0 0
I am sure it's bit tricky. Any help is appreciated.