text_html_output_1.png
from wordcloud import WordCloud

import matplotlib.pyplot as plt

import pandas as pd

def visualize_word_counts(counts):
    wc = WordCloud(max_font_size=130, min_font_size=25, colormap='tab20', background_color='white', 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_gender_dying_corr = {}
country_gender_suicide_corr = {}
for val, df in data.groupby('Country'):
    corr_gender_dying = df['ProbDyingMale'].corr(df['ProbDyingFemale'])
    corr_gender_suicide = df['SuicideMale'].corr(df['SuicideFemale'])
    country_gender_dying_corr[val] = corr_gender_dying
    country_gender_suicide_corr[val] = corr_gender_suicide

visualize_word_counts(data.groupby('Country').mean()['SuicideBoth'].to_dict())