Created
July 27, 2020 06:57
-
-
Save naenumtou/44c5f3f4ab905f11e88a5e8509429f9f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Calculation | |
#Marginal cases | |
l = list(df.columns) | |
l = l[2:] | |
for i in l: | |
df['daily_'+str(i)] = df.groupby(['country'])[str(i)].diff(1).fillna(df[str(i)]) | |
#Decrease cumulative | |
df['current'] = df['cases'] - df['recovered'] - df['deaths'] | |
l.append('current') | |
#Normalization | |
nor = df.groupby('country').transform(lambda x: (x - x.min()) / (x.max() - x.min())) | |
nor = nor[l] | |
nor = nor.add_prefix('nor_') | |
df = pd.merge(df, nor, how='left', left_index = True, right_index = True) | |
#Cumulative | |
cum = df.groupby('country').transform(lambda x: (x / x.sum())) | |
cum = cum[l] | |
cum = cum.add_prefix('cum_') | |
df = pd.merge(df, cum, how='left', left_index = True, right_index = True) | |
#Standardization | |
std = df.groupby('country').transform(lambda x: (x - x.mean()) / x.std()) | |
std = std[l] | |
std = std.add_prefix('std_') | |
df = pd.merge(df, std, how='left', left_index = True, right_index = True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment