Created
March 6, 2020 14:55
-
-
Save mashhadazam/cf45be79b43ab30a4c5a3fafaf9de4d6 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
### Get Countrywise Data | |
def countrydata(df_cleaned,oldname,newname): | |
df_country=df_cleaned.groupby(['Country/Region','Date'])['Cases'].sum().reset_index() | |
df_country=df_country.set_index(['Country/Region','Date']) | |
df_country.index=df_country.index.set_levels([df_country.index.levels[0], pd.to_datetime(df_country.index.levels[1])]) | |
df_country=df_country.sort_values(['Country/Region','Date'],ascending=True) | |
df_country=df_country.rename(columns={oldname:newname}) | |
return df_country | |
ConfirmedCasesCountry=countrydata(ConfirmedCases,'Cases','Total Confirmed Cases') | |
DeathsCountry=countrydata(Deaths,'Cases','Total Deaths') | |
RecoveriesCountry=countrydata(Recoveries,'Cases','Total Recoveries') | |
### Get DailyData from Cumulative sum | |
def dailydata(dfcountry,oldname,newname): | |
dfcountrydaily=dfcountry.groupby(level=0).diff().fillna(0) | |
dfcountrydaily=dfcountrydaily.rename(columns={oldname:newname}) | |
return dfcountrydaily | |
NewCasesCountry=dailydata(ConfirmedCasesCountry,'Total Confirmed Cases','Daily New Cases') | |
NewDeathsCountry=dailydata(DeathsCountry,'Total Deaths','Daily New Deaths') | |
NewRecoveriesCountry=dailydata(RecoveriesCountry,'Total Recoveries','Daily New Recoveries') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment