title: How to calculate average on a subset of a subset of a dataframe in Python?
body: <p>I'm trying to calculate the average of a subset of a subset of data.</p>
  
  <p>For example, imagine my data is</p>
  
  <pre><code> **Family Name / Gender / Grade**
      Smith / Male / 90
      Smith / Male / 85
      Smith / Female / 65
      Smith / Female / 100
      Johns / Male / 95
      Johns / Male / 45
      Johns / Female / 20
      Johns / Female / 100
  </code></pre>
  
  <p>So what I am trying to do is calculate the average grades of the females in the Smith family. The answer would be (65+100)/2.</p>
  
  <p>I know how to calculate it the mean, but I do not know how to break it into subcategories twice.</p>
  
  <p>My code is:</p>
  
  <pre><code>numpy.mean(students.grade)
  </code></pre>
  
  <p>I also tried a method where I did:</p>
  
  <pre><code>smith_family = students[students['Family Name'] == 'Smith']
  np.mean(smith_family.grades)
  </code></pre>
  
  <p>But this method isn't scalable because I would have to manually type in every family name.</p>
  
  <p>I made up the data; I'm actually doing it with animals and people's ratings of animals but its the same concept.</p>
  
  <p>P.S. I'm using Python.</p>