text_plain_output_1.png
import numpy as np

import pandas as pd

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')}

def repeated_measures_effect_size(country, col1, col2):
    col1, col2 = (countries[country][col1], countries[country][col2])
    m1, m2 = (np.mean(col1), np.mean(col2))
    s1, s2 = (np.std(col1), np.std(col2))
    r = col1.corr(col2)
    s_z = np.sqrt(s1 ** 2 + s2 ** 2 - 2 * r * s1 * s2)
    s_rm = s_z / np.sqrt(2 * (1 - r))
    return (m1 - m2) / s_rm

effect_sizes_dying = {c: repeated_measures_effect_size(c, 'ProbDyingMale', 'ProbDyingFemale') for c in countries}
effect_sizes_dying = dict(sorted(effect_sizes_dying.items(), key=lambda x: x[1]))

for c in reversed(list(effect_sizes_dying.keys())[-5:]):
    print(c)