Sort lists in a Pandas Dataframe column
<p>I have a Dataframe column which is a collection of lists</p>

<pre><code>    a
['a', 'b']
['b', 'a']
['a', 'c']
['c', 'a']
</code></pre>

<p>I would like to use this list to group by its unique values (['a', 'b'] &amp; ['a', 'c']). However, this generates an error </p>

<pre><code>TypeError: unhashable type: 'list'
</code></pre>

<p>Is there any way around this. Ideally I would like to sort the values in place and create an additional column of a concatenated string.</p>

<p>list are unhashable.  however, tuples are hashable</p>

<p>use</p>

<pre><code>df.groupby([df.a.apply(tuple)])
</code></pre>

<p><strong><em>setup</em></strong><br>
<code>df = pd.DataFrame(dict(a=[list('ab'), list('ba'), list('ac'), list('ca')]))</code><br>
<strong><em>results</em></strong><br>
<code>df.groupby([df.a.apply(tuple)]).size()</code></p>

<pre><code>a
(a, b)    1
(a, c)    1
(b, a)    1
(c, a)    1
dtype: int64
</code></pre>

python pandas