|
|
@ -1 +1,61 @@ |
|
|
|
import pandas as pd |
|
|
|
import matplotlib.pyplot as plt |
|
|
|
import matplotlib.dates as mdates |
|
|
|
import numpy as np |
|
|
|
import datetime |
|
|
|
import math |
|
|
|
from scipy import interpolate |
|
|
|
plt.rcParams['font.sans-serif'] = ['SimHei'] |
|
|
|
plt.rcParams['axes.unicode_minus'] = False |
|
|
|
|
|
|
|
#打开数据文件 |
|
|
|
dataset = pd.read_csv('E:\dase intro\COVID-19Analysis\COVID-19\covid-19-all.csv') |
|
|
|
|
|
|
|
#数据预处理 |
|
|
|
def parse_ymd(s): |
|
|
|
year_s, mon_s, day_s = s.split('-') |
|
|
|
return datetime.datetime(int(year_s), int(mon_s), int(day_s)).strftime("%Y-%m-%d") |
|
|
|
|
|
|
|
dataset = dataset.fillna(0) |
|
|
|
|
|
|
|
dataset['Date'] = pd.to_datetime(dataset['Date']) |
|
|
|
|
|
|
|
#对China数据进行可视化操作 |
|
|
|
China = dataset[dataset['Country/Region'] == 'China'].reset_index(drop=True) |
|
|
|
|
|
|
|
#计算每日治愈率/确诊人数/治愈人数(分月份显示) |
|
|
|
dfChinaJan = China[China['Date'].dt.month == 1] |
|
|
|
dfChinaFeb = China[China['Date'].dt.month == 2] |
|
|
|
dfChinaMar = China[China['Date'].dt.month == 3] |
|
|
|
dfChinaApr = China[China['Date'].dt.month == 4] |
|
|
|
dfChinaMay = China[China['Date'].dt.month == 5] |
|
|
|
dfChinaJun = China[China['Date'].dt.month == 6] |
|
|
|
dfChinaJul = China[China['Date'].dt.month == 7] |
|
|
|
dfChinaAug = China[China['Date'].dt.month == 8] |
|
|
|
dfChinaSept = China[China['Date'].dt.month == 9] |
|
|
|
dfChinaOct = China[China['Date'].dt.month == 10] |
|
|
|
dfChinaNov = China[China['Date'].dt.month == 11] |
|
|
|
dfChinaDec = China[China['Date'].dt.month == 12] |
|
|
|
|
|
|
|
confirmed = [dfChinaJan['Confirmed'].sum(),dfChinaFeb['Confirmed'].sum(),dfChinaMar['Confirmed'].sum(),dfChinaApr['Confirmed'].sum(), |
|
|
|
dfChinaMay['Confirmed'].sum(),dfChinaJun['Confirmed'].sum(),dfChinaJul['Confirmed'].sum(),dfChinaAug['Confirmed'].sum(), |
|
|
|
dfChinaSept['Confirmed'].sum(),dfChinaOct['Confirmed'].sum(),dfChinaNov['Confirmed'].sum(),dfChinaDec['Confirmed'].sum()] |
|
|
|
recovered = [dfChinaJan['Recovered'].sum(),dfChinaFeb['Recovered'].sum(),dfChinaMar['Recovered'].sum(),dfChinaApr['Recovered'].sum(), |
|
|
|
dfChinaMay['Recovered'].sum(),dfChinaJun['Recovered'].sum(),dfChinaJul['Recovered'].sum(),dfChinaAug['Recovered'].sum(), |
|
|
|
dfChinaSept['Recovered'].sum(),dfChinaOct['Recovered'].sum(),dfChinaNov['Recovered'].sum(),dfChinaDec['Recovered'].sum()] |
|
|
|
recoverPoss = [] |
|
|
|
for i in range(len(confirmed)): |
|
|
|
recoverPoss.append(recovered[i] / confirmed[i]) |
|
|
|
|
|
|
|
date = pd.date_range(start='2020-01', periods=12, freq="m").strftime('%Y-%m') |
|
|
|
data_1={ |
|
|
|
'confirmed':confirmed, |
|
|
|
'recovered':recovered, |
|
|
|
'recoverPoss':recoverPoss |
|
|
|
} |
|
|
|
data_1_df = pd.DataFrame(data_1, index=date) |
|
|
|
ax = data_1_df.plot(secondary_y=['recovery possibility'], x_compat=True, grid=True) |
|
|
|
ax.set_ylabel('confirmed/recovered') |
|
|
|
ax.grid(linestyle="--", alpha=0.3) |
|
|
|
|
|
|
|
plt.show() |