sidsriv / Introduction-to-Data-Science-in-python

This repository contains Ipython notebooks of assignments and tutorials used in the course introduction to data science in python, part of Applied Data Science using Python Specialization from University of Michigan offered by Coursera
216 stars 437 forks source link

Assignment 2, Q6, your result is not correct I think... #3

Open OwenZzzz opened 4 years ago

OwenZzzz commented 4 years ago

My result is ['California', 'Texas', 'Illinois'], after doublecheck I suppose its the right answer. Basically the ranking didn't operate correctly in your code I think.

And my code below for your reference

def answer_six():

x = census_df[census_df['SUMLEV'] == 50]
x['sort_result'] = x['CENSUS2010POP'].groupby(x['STNAME']).rank(ascending = False)
max_3 = x[x['sort_result']<=3]
summed_max_3 = max_3.groupby(max_3['STNAME'])['CENSUS2010POP'].sum().sort_values(ascending = False)

return list(summed_max_3.index[:3].values)

answer_six()

jjdixon commented 4 years ago

I wrote this one up too. I got the same answer as you for what its worth.