Last active
September 26, 2020 02:22
-
-
Save alinazhanguwo/5b31cbab9ca8c1d9b5bfccc89ec46480 to your computer and use it in GitHub Desktop.
compute the delta between two consecutive dates in number of Deaths for top 10 states in America
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
# top 10 states in America | |
'''['California', | |
'Florida', | |
'Georgia', | |
'Illinois', | |
'Massachusetts', | |
'Michigan', | |
'New Jersey', | |
'New York', | |
'Pennsylvania', | |
'Texas']''' | |
COL_STATES = bar_plot_df['Province/State'].tolist() | |
mask_september = df['ObservationDate']>='09/01/2020' | |
COL_HEATMAP = ['Country/Region', 'Province/State', 'Deaths', 'Confirmed', 'ObservationDate' ] | |
all_delta_df = pd.DataFrame() | |
delta_df = pd.DataFrame() | |
for STATE in COL_STATES: | |
mask_one_state = df['Province/State']==STATE | |
delta_df = pd.DataFrame() | |
delta_df = df[mask_one_state & mask_september][COL_HEATMAP] | |
delta_df['Delta_Deaths_'+STATE] = delta_df.Deaths.diff() | |
if STATE=='California': | |
all_delta_df[['ObservationDate', 'Delta_Deaths_'+STATE]] = delta_df[['ObservationDate', 'Delta_Deaths_'+STATE]].copy() | |
else: | |
all_delta_df = pd.merge(all_delta_df, delta_df[['ObservationDate', 'Delta_Deaths_'+STATE]], how='left', on='ObservationDate') | |
COL_DELATA = all_delta_df.columns.tolist() | |
COL_DELATA.remove('ObservationDate') | |
all_delta_df.dropna(inplace=True) | |
all_delta_df[COL_DELATA] = all_delta_df[COL_DELATA].astype(int) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment