Untitled
unknown
plain_text
16 days ago
2.6 kB
2
Indexable
Never
indicator_code = 'SP.POP.65UP.TO.ZS' population_65_above = worlddata[worlddata['IndicatorCode'] == indicator_code] population_65_above = population_65_above.sort_values('Year', ascending=False).drop_duplicates(subset=['CountryCode']) global_average = population_65_above['Value'].mean() above_average_data = population_65_above[population_65_above['Value'] > global_average] below_average_data = population_65_above[population_65_above['Value'] <= global_average] fig = px.choropleth(population_65_above, locations='CountryCode', color='Value', hover_name='CountryName', title='Population Ages 65+ for All Countries', labels={'Value': 'Population 65+ (%)'}, projection='natural earth') fig.update_traces(visible=True) fig.add_trace(px.choropleth(above_average_data, locations='CountryCode', color='Value', hover_name='CountryName', title='Countries with Population Ages 65+ Above Average', labels={'Value': 'Population 65+ (%)'}, projection='natural earth').data[0]) fig.add_trace(px.choropleth(below_average_data, locations='CountryCode', color='Value', hover_name='CountryName', title='Countries with Population Ages 65+ Below Average', labels={'Value': 'Population 65+ (%)'}, projection='natural earth').data[0]) fig.update_layout( updatemenus=[{ 'buttons': [ { 'method': 'update', 'label': 'All Countries', 'args': [{'visible': [True, False, False]}, {'title': 'Population Ages 65+ for All Countries'}] }, { 'method': 'update', 'label': 'Above Average', 'args': [{'visible': [False, True, False]}, {'title': 'Countries with Population Ages 65+ Above Average'}] }, { 'method': 'update', 'label': 'Below Average', 'args': [{'visible': [False, False, True]}, {'title': 'Countries with Population Ages 65+ Below Average'}] } ], 'direction': 'down', 'showactive': True }] ) fig.show()
Leave a Comment