introduction to data science with python // assignment 3 question 3

533 Views Asked by At

i am facing problem while answering the assignment ,

can anyone help me with it ?

Question 3¶ What are the top 15 countries for average GDP over the last 10 years?

This function should return a Series named avgGDP with 15 countries and their average GDP sorted in descending order.



`def answer_three():
    Top15 = answer_one()
    years = ['2006', '2007', '2008', '2009', '2010', '2011', '2012', '2013', '2014', '2015']
    return (Top15[years].mean(axis=1)).sort_values(ascending=False).rename('avgGDP')`
1

There are 1 best solutions below

1
Michel On

Another way:

      def answer_three():
          frames = ["2006","2007","2008","2009","2010",
                   "2011","2012","2013","2014","2015"]
          y = answer_one()
          avgGDP = (y[frames].apply(lambda z:  mean(z),axis=1)).sort_values(ascending   = False)
          return avgGDP