title: Aggregating sorting function in Pandas Data frame
body: <p>I have a data frame which look like this:</p>
  
  <pre><code>    ID     Time                Quantity   Type
      1     2019-04-03 05:51:54        0    Dog|Cat
      2     2019-05-03 05:51:54        0    Dog
      3     2019-04-02 05:51:54        0    Pig|Cat
      4     2019-04-03 05:51:54        2    
      4     2019-07-03 04:51:54        0    Dog|Cat|Pig
      3     2019-04-09 05:51:54        4    
  </code></pre>
  
  <p>There is also a dictonry to sort the type column:</p>
  
  <pre class="lang-py prettyprint-override"><code>    dictionary = {'Cat': 1,'Dog': 2,'Pig': 3}
  </code></pre>
  
  <p>I would like to group the table by ID and get the max for the other 3 columns. I have used this to group the first two:</p>
  
  <pre class="lang-py prettyprint-override"><code>    df.groupby(['ID']).agg({'Time':'max','Quantity':'max'})
  </code></pre>
  
  <p>What I'm having trouble with is integrating the additional code to get the max value from the dictionary into the aggregate function. I think it should be something like this:</p>
  
  <pre class="lang-py prettyprint-override"><code>    max(df['Type'].str.split(pat='|'), key=lambda s: dictionary[s])
  </code></pre>
  
  <p>My idea output would be:</p>
  
  <pre><code>    ID     Time                Quantity   Type
      1     2019-04-03 05:51:54        0    Dog
      2     2019-05-03 05:51:54        0    Dog
      3     2019-04-09 05:51:54        4    Pig
      4     2019-07-03 04:51:54        2    Pig
  </code></pre>
  
  <p>I'm sorry if I'm missing something elementary as I'm fairly new to using pandas </p>