title: Python How to find average of columns using dataframes apply method
body: <p>This is a question on Udacity Data Science Nanodegree and I can't figure it out. The instructions are:</p>
  
  <p>Using the dataframe's apply method, create a new Series called <code>avg_medal_count</code> that indicates the average number of gold, silver, and bronze medals earned amongst countries who earned at least one medal of any kind at the 2014 Sochi Olympics.</p>
  
  <p>The code I have currently is:</p>
  
  <pre><code>import numpy
  from pandas import DataFrame, Series
  
  def avg_medal_count():
  
   countries = ['Russian Fed.', 'Norway', 'Canada', 'United States',
                   'Netherlands', 'Germany', 'Switzerland', 'Belarus',
                   'Austria', 'France', 'Poland', 'China', 'Korea', 
                   'Sweden', 'Czech Republic', 'Slovenia', 'Japan',
                   'Finland', 'Great Britain', 'Ukraine', 'Slovakia',
                   'Italy', 'Latvia', 'Australia', 'Croatia', 'Kazakhstan']
  
      gold = [13, 11, 10, 9, 8, 8, 6, 5, 4, 4, 4, 3, 3, 2, 2, 2, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0]
      silver = [11, 5, 10, 7, 7, 6, 3, 0, 8, 4, 1, 4, 3, 7, 4, 2, 4, 3, 1, 0, 0, 2, 2, 2, 1, 0]
      bronze = [9, 10, 5, 12, 9, 5, 2, 1, 5, 7, 1, 2, 2, 6, 2, 4, 3, 1, 2, 1, 0, 6, 2, 1, 0, 1]
  
      olympic_medal_counts = {'country_name':countries,
                              'gold': Series(gold),
                              'silver': Series(silver),
                              'bronze': Series(bronze)}    
      df = DataFrame(olympic_medal_counts)
  
  
  # YOUR CODE HERE
  
  
      return avg_medal_count
  </code></pre>
  
  <p>I have tried a couple different things such as:</p>
  
  <p><code>avg_medal_count = df.apply(numpy.mean)</code>, but get the error saying it could not convert the first column to numeric which makes sense because the first column is a list of countries. How can I use <code>df.apply</code> on only gold, silver and bronze columns? I have tried other variations, but nothing worked. I am pretty sure that I need to use a combination of <code>df.apply</code> and <code>numpy.mean</code>, because that is what I just learned about. Any thoughts? </p>
  
  <p>Thanks!</p>