title: Groupby two columns in pandas, and perform operations over totals for each group
body: <p>The code below:</p>
  <pre><code>df = pd.read_csv('./filename.csv', header='infer').dropna()
  
  df.groupby(['category_code','event_type']).event_type.count().head(20)
  </code></pre>
  <p>Returns the following table:</p>
  <p><a href="https://i.stack.imgur.com/ok7YV.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ok7YV.png" alt="enter image description here" /></a></p>
  <p>How can I obtain, for all the sub groups under event_type that have both &quot;purchase&quot; and &quot;view&quot;, the ratio between the total of &quot;purchase&quot; and the total of &quot;view&quot;?</p>
  <p>In this specific case, for instance, I need a function that returns:</p>
  <p>1/57</p>
  <p>1/232</p>
  <p>3/249</p>
  <p>Eventually, I will need to plot such result.</p>
  <p>I have been trying for a day, without success. I am still new to pandas, and I searched across every possible forum without finding anything useful.</p>