text_html_output_1.png
from wordcloud import WordCloud

import geopandas

import matplotlib.pyplot as plt

import pandas as pd

def visualize_word_counts(counts, show=True):
    wc = WordCloud(max_font_size=130, min_font_size=25, colormap='tab20', background_color='black', prefer_horizontal=0.95, width=2100, height=700, random_state=0)
    cloud = wc.generate_from_frequencies(counts)
    plt.axis('off')

data = pd.read_csv('../input/suicide-rates-worldwide-20002019/data.csv')

columns = ['Country', 'Year', 'ProbDyingBoth', 'ProbDyingMale', 'ProbDyingFemale', 'SuicideBoth', 'SuicideMale', 'SuicideFemale']
values = data.iloc[1:, :].values
data = pd.DataFrame(values, columns=columns)
for col in columns[2:]:
    data[col] = data[col].map(lambda x: x.split('[')[0]).astype('float')

data.sample(5)

countries = {val: df for val, df in data.groupby('Country')}
country_avg = data.groupby('Country').mean().reset_index()

fig, ax = plt.subplots(nrows=1, ncols=2, figsize=(15,6))

ax[0].plot([0,60],[0,60], linewidth=3, color='black')
sns.scatterplot(data=country_avg, x='ProbDyingMale', y='ProbDyingFemale', s=100, ax=ax[0])
ax[0].set_title('Dying rates by gender')

ax[1].plot([0,100],[0,100], linewidth=3, color='black')
sns.scatterplot(data=country_avg, x='SuicideMale', y='SuicideFemale', s=100, ax=ax[1])
ax[1].set_title('Suicide rates by gender')

plt.show()

country_avg.sort_values(by='ProbDying_male_minus_female')

world = geopandas.read_file(geopandas.datasets.get_path('naturalearth_lowres'))

geopandas_countryname_correction = {'Bosnia and Herz.': 'Bosnia and Herzegovina', 'Brunei': 'Brunei Darussalam', 'Central African Rep.': 'Central African Republic', 'Dem. Rep. Congo': 'Democratic Republic of the Congo', 'Dominican Rep.': 'Dominican Republic', 'Eq. Guinea': 'Equatorial Guinea', 'eSwatini': 'Eswatini', 'Laos': "Lao People's Democratic Republic", 'Macedonia': 'North Macedonia', 'Moldova': 'Republic of Moldova', 'Russia': 'Russian Federation', 'United Kingdom': 'United Kingdom of Great Britain and Northern Ireland', 'Tanzania': 'United Republic of Tanzania', 'Vietnam': 'Viet Nam', 'Syria': 'Syrian Arab Republic', 'S. Sudan': 'South Sudan', 'Solomon Is.': 'Solomon Islands', 'North Korea': "Democratic People's Republic of Korea"}

world['Country'] = world['name'].map(geopandas_countryname_correction).fillna(world['name'])
world_merged = world.merge(country_avg, on='Country', how='left')

world_merged.plot(column='ProbDyingBoth', legend=True, figsize=(15, 8), missing_kwds={'color': 'lightgrey', 'label': 'Missing values'})
plt.title('Overall dying rates for both genders')
plt.show()