I have a DataFrame containing a column, props
, which contains lists of strings.
Ideally, I\'d like to group by this column, but I predictably get an err
You can use the immutable counterpart to lists, which are tuples:
>>> import pandas as pd
>>> df = pd.DataFrame([[[1, 2], 'ab'], [[2, 3], 'bc']])
>>> df.groupby(0).groups
...
... TypeError: unhashable type: 'list'
You could apply the conversion on the appropriate column:
>>> df[0] = df[0].apply(tuple)
>>> df.groupby(0).groups
{(1, 2): [0], (2, 3): [1]}