title: manipulating a pandas dataframe column containing a list
body: <p>I have used the following code with the unique() function in pandas to create a column which then contains a list of unique values:</p>
  
  <pre><code>import pandas as pd
  from collections import OrderedDict
  dct = OrderedDict([
  ('referencenum',['10','10','20','20','20','30','30','40']),
  ('Month',['Jan','Jan','Jan','Feb','Feb','Feb','Feb','Mar']),
  ('Category',['good','bad','bad','bad','bad','good','bad','bad'])
                   ])
  df = pd.DataFrame.from_dict(dct)
  </code></pre>
  
  <p>This gives the following sample dataset:</p>
  
  <pre><code>  referencenum Month Category
  0           10   Jan     good
  1           10   Jan      bad
  2           20   Jan      bad
  3           20   Feb      bad
  4           20   Feb      bad
  5           30   Feb     good
  6           30   Feb      bad
  7           40   Mar      bad
  </code></pre>
  
  <p>Then I summarise as follows:</p>
  
  <pre><code>dfsummary = pd.DataFrame(df.groupby(['referencenum', 'Month'])['Category'].unique())
  dfsummary.reset_index()
  </code></pre>
  
  <p>To give the summary dataframe with "Category" column containing a list</p>
  
  <pre><code>referencenum    Month         Category
  0   10          Jan           [good, bad]
  1   20          Feb           [bad]
  2   20          Jan           [bad]
  3   30          Feb           [good, bad]
  4   40          Mar           [bad]
  </code></pre>
  
  <p>My question is how do I obtain another column containing the len() or number of items in the Category "list" column?</p>
  
  <p>Also - how do extract the first/ second item in the list to another column? </p>
  
  <p>Can I do these manipulations within pandas or do I somehow need to drop out to list manipulations and then come back to pandas?</p>
  
  <p>Many thanks!</p>