def answer_six():
census_df = pd.read_csv('census.csv')
copy = census_df.copy()
states = copy['STNAME'].unique()
counties = copy['CTYNAME']
play = copy.copy()
play = play.set_index(['STNAME','CTYNAME'])
copy = copy.set_index(['STNAME'])
def population_with_top3 (state):
counties = copy.loc[state]['CTYNAME'].values
population_array = list(map(lambda county:int(play.loc[state,county]['CENSUS2010POP'].values),counties))
population_array.sort(reverse = True)
population = population_array[1] + population_array[2] + population_array[3]
return {'STNAME': state, 'POP': population}
states_with_pop = list(map(population_with_top3,states))
return states_with_pop
answer_six()
when running the code I get:
TypeError: only length-1 arrays can be converted to Python scalars
Does anybody have any experience with this kind of issue?
Thanks!