Skip to content Skip to sidebar Skip to footer

How To Create Binary Representations Of Words In Pandas Column?

I have a column which contains lists of variable sizes. The lists contain a limited amount of short text values. Around 60 unique values all together. 0 ['AC','BB'] 1 ['AD','

Solution 1:

Here's one way:

df = pd.get_dummies(df.explode('val')).sum(level = 0)

NOTE: Here (level=0) is kind of like a grouping operation that uses an index for grouping stuff. So, I prefer to use this after exploding the dataframe.

Post a Comment for "How To Create Binary Representations Of Words In Pandas Column?"