Skip to content

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

Description

@OwenZzzz

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()

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions