def generate_worldmap(df_nation_counts): """displays a worldmap coded with the pygal-library in HTML format (interactive Chart) Parameters: Nations Count Dataframe Returns: HTML worldmap """ total_dict = df_nation_counts.set_index('Nation').to_dict('dict').get('Anzahl Gesuche') dict_1_5000 = dict(filter(lambda elem: elem[1] <= 5000, total_dict.items())) dict_5000_20000 = dict(filter(lambda elem: (elem[1] > 5000 and elem[1] <= 20000), total_dict.items())) dict_20000_plus = dict(filter(lambda elem: (elem[1] > 20000), total_dict.items())) base_html = """ <!DOCTYPE html> <html> <head> <script type="text/javascript" src="https://kozea.github.io/pygal.js/2.0.x/pygal-tooltips.min.js"></script> <script type="text/javascript" src="http://kozea.github.com/pygal.js/javascripts/pygal-tooltips.js"></script> </head> <body> <figure> {rendered_chart} </figure> </body> </html> """ #styles custom_style = Style( colors=('#e4ed80', '#7dccbc', '#63192e'), tooltip_font_size=8, legend_font_size=7, title_font_size=10, background='#ffffff') #define chart worldmap_chart = World(style=custom_style) worldmap_chart.title = 'Anzahl Asylgesuche nach Nation' worldmap_chart.add('1-5000 Gesuche', dict_1_5000) worldmap_chart.add('5000-20000 Gesuche', dict_5000_20000) worldmap_chart.add('20000+ Gesuche', dict_20000_plus) #render rendered_chart = worldmap_chart.render(is_unicode=True) plot_html = base_html.format(rendered_chart=rendered_chart) return display(HTML(plot_html))