One approach with str.join + str.get_dummies:
out = df['x'].str.join(',').str.get_dummies(',')
out:
abc bac cab
0 1 1 1
1 0 1 0
2 1 0 1
Or with explode + pd.get_dummies then groupby max:
out = pd.get_dummies(df['x'].explode()).groupby(level=0).max()
out:
abc bac cab
0 1 1 1
1 0 1 0
2 1 0 1
Can also do pd.crosstab after explode if want counts instead of dummies:
s = df['x'].explode()
out = pd.crosstab(s.index, s)
out:
x abc bac cab
row_0
0 1 1 1
1 0 1 0
2 1 0 1
*Note output is the same here, but will be count if there are duplicates.
DataFrame:
import pandas as pd
df = pd.DataFrame({
'x': [['abc', 'bac', 'cab'], ['bac'], ['abc', 'cab']]
})
df.to_dict()