import matplotlib.pyplot as plt import pandas as pd """ #=========================================================================================================== # Copyright (c) 2006-2020 Paseman & Associates (www.paseman.com). All rights reserved. #=========================================================================================================== Written in Python 3 source activate base idle3 & Sources: https://www.arcgis.com/apps/opsdashboard/index.html#/bda7594740fd40299423467b48e9ecf6 https://www.worldometers.info/coronavirus/ # https://www.kaggle.com/datasets '/kaggle/input/novel-corona-virus-2019-dataset/2019_nCoV_data.csv' # https://stackoverflow.com/questions/43121584/matplotlib-scatterplot-x-axis-labels #plt.semilogy(df2[[columnLabel]],label=region) Excel format of the COVID-19 data from Johns Hopkins University (https://lnkd.in/e-eBqNJ). https://lnkd.in/er34ByJ <-covid-19-data.xlsx April 15th peak http://www.healthdata.org/ """ #=========================================================================================================== def extractTimeSeries(targetRow,columnLabel,title,path="20200402/"): dateIndex=4 dates = targetRow.columns[dateIndex:] data = targetRow[dates].values[0] df = pd.DataFrame(data,index=dates,columns=[columnLabel]) # https://pandas.pydata.org/pandas-docs/version/0.24.2/reference/api/pandas.Series.plot.html t= title+" "+columnLabel ax=df[[columnLabel]].plot(title=t,logy=True) ax.set_ylabel("People") ax.set_xlabel("Date") ax.get_figure().savefig(path+t) df["velocity"] = df[columnLabel] - df[columnLabel].shift(1) df["acceleration"] = df["velocity"] - df["velocity"].shift(1) ax=df[["velocity","acceleration"]].plot(title=t,logy=True) ax.set_ylabel("People") ax.set_xlabel("Date") ax.get_figure().savefig(path+t+"velacc") print(t,"\n",df) #=========================================================================================================== # https://www.interviewqs.com/ddi_code_snippets/rows_cols_python predicate1 = lambda df,region: df.loc[(df[(u'Country/Region')] == region)] predicate2 = lambda df,region,state: df.loc[(df[(u'Country/Region')] == region) & (df[(u'Province/State')] == state)] def processJHU(): # https://coronavirus.jhu.edu/map.html # https://data.humdata.org/dataset/novel-coronavirus-2019-ncov-cases for columnLabel,src in [ ("deaths","https://data.humdata.org/hxlproxy/api/data-preview.csv?url=https%3A%2F%2Fraw.githubusercontent.com%2FCSSEGISandData%2FCOVID-19%2Fmaster%2Fcsse_covid_19_data%2Fcsse_covid_19_time_series%2Ftime_series_covid19_deaths_global.csv&filename=time_series_covid19_deaths_global.csv"), ("recovered","https://data.humdata.org/hxlproxy/api/data-preview.csv?url=https%3A%2F%2Fraw.githubusercontent.com%2FCSSEGISandData%2FCOVID-19%2Fmaster%2Fcsse_covid_19_data%2Fcsse_covid_19_time_series%2Ftime_series_covid19_recovered_global.csv&filename=time_series_covid19_recovered_global.csv"), ("confirmed","https://data.humdata.org/hxlproxy/api/data-preview.csv?url=https%3A%2F%2Fraw.githubusercontent.com%2FCSSEGISandData%2FCOVID-19%2Fmaster%2Fcsse_covid_19_data%2Fcsse_covid_19_time_series%2Ftime_series_covid19_confirmed_global.csv&filename=time_series_covid19_confirmed_global.csv")]: #src= "time_series_covid19_confirmed_global.csv" #src= "time_series_covid19_deaths_global.csv"; columnLabel="deaths" df = pd.read_csv(src) extractTimeSeries(predicate1(df,'US'),columnLabel,title='US') extractTimeSeries(predicate1(df,'Italy'),columnLabel,title='Italy') extractTimeSeries(predicate2(df,'China','Hubei'),columnLabel,title='China Hubei') plt.show() #=========================================================================================================== if __name__ == '__main__': processJHU()