If we have a column like:
Name
0 Alice
1 Bob
2 Dave
then, after numeric encoding, it becomes:
Name
0 0
1 1
2 2
What if, however, we have a column like this:
Names
0 Alice, Bob
1 Alice, Bob, Dave
2 Dave
One way to encode it would be like this:
Alice Bob Dave
0 1 1 0
1 1 1 1
2 0 0 1
However, this creates a lot of extra columns. Is there a way to encode such a column in a way that doesn't end up with loads of extra columns, just like using numeric encoding instead of one-hot-encoding prevents too many columns from appearing in a column like the first one I showed?
If you're using Python, here's some code to reproduce my DataFrame:
import pandas as pd
df = pd.DataFrame({'Names': ['Alice, Bob', 'Alice, Bob, Dave', 'Dave']})
Edit: the ultimate purpose of this is to then pass this through a tree-based classifier.