title: Pandas - aggregate over inconsistent values types (string vs list)
body: <p>Given the following DataFrame, I try to aggregate over columns <code>'A'</code> and <code>'C'</code>. for <code>'A'</code>, count unique appearances of the strings, and for <code>'C'</code>, sum the values. </p>
  
  <p>Problem arises when some of the samples in <code>'A'</code> are actually lists of those strings. </p>
  
  <p>Here's a simplified example:</p>
  
  <pre><code>df = pd.DataFrame({'ID': [1, 1, 1, 1, 1, 2, 2, 2], 
                 'A' : ['a', 'a', 'a', 'b', ['b', 'c', 'd'], 'a', 'a', ['a', 'b', 'c']],
                 'C' : [1, 2, 15, 5, 13, 6, 7, 1]})
  df
  Out[100]: 
     ID          A   C
  0   1          a   1
  1   1          a   2
  2   1          a  15
  3   1          b   5
  4   1  [b, c, d]  13
  5   2          a   6
  6   2          a   7
  7   2  [a, b, c]   1
  
  aggs = {'A' : lambda x: x.nunique(dropna=True),
          'C' : 'sum'}
  
  # This will result an error: TypeError: unhashable type: 'list'
  agg_df = df.groupby('ID').agg(aggs)
  </code></pre>
  
  <p>I'd like the following output:</p>
  
  <pre><code>print(agg_df)
      A   C
  ID       
  1   4  36
  2   3  14
  </code></pre>
  
  <p>Which resulted because for <code>'ID' = 1</code> we had <code>'a', 'b', 'c' and 'd</code>' and for <code>'ID' = 2</code>, we had <code>'a', 'b', 'c'</code>.</p>