title: Get first line in each hierarchical pandas series
body: <p>This is my Dataframe</p>
  
  <pre><code>import pandas as pd
  
  df = pd.DataFrame({
      "Gender": ["M", "F", "M", "M", "M",  "F", "F", "F", "F", "F", "F"],
      "Work-code": ["N1", "N3", "N1", "N1", "X15", "N3", "N3", "N3", "N3", "N1", "N3"],
      "Accident-type-code": ["1.1","1.2", "1.1","1.3","1.5","1.3","1.1","1.1","1.1", "1.1", "1.3"]
  })
  </code></pre>
  
  <p>To analise this data I'm using groupby:</p>
  
  <pre><code>data = df.groupby(["Gender", "Work-code"])["Accident-type-code"].value_counts()
  </code></pre>
  
  <p>This is what I get:</p>
  
  <pre><code>Gender  Work-code  Accident-type-code
  F       N1         1.1                   1
          N3         1.1                   3
                     1.3                   2
                     1.2                   1
  M       N1         1.1                   2
                     1.3                   1
          X15        1.5                   1
  </code></pre>
  
  <p>What I need is just the first line of each inner group (the most frequent group for a given outer group), like:</p>
  
  <pre><code>Gender  Work-code  Accident-type-code
  F       N1         1.1                   1
          N3         1.1                   3
  M       N1         1.1                   2
          X15        1.5                   1
  </code></pre>
  
  <p>In fact, I'm doing this because I want to do a bivariate frequency distribution, but I don't know any function or library in python to do this.</p>