目录

改进的SIR差分模型及三个模型的应用

前言

感谢组员的共同协作,做组长的有些东西帮不上实在抱歉。

改进的SIR差分模型

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
%% SIR差分模型
frame=importdata('美国covid19疫情数据l-history改.csv');
date_row=size(frame.data,1);
data=frame.data;
date=frame.textdata(:,1);
real_date=date(2:date_row+1,:);
E=zeros(2,90);
l=0.000125;    %日接触率
m=0.01;   %日治愈率0.0005
E(1,1)=data(345,12)/300000000;
E(2,1)=1-E(1,1);
for i=1:90
    E(1,i+1)=l*E(2,i)-m*E(1,i)+E(1,i);
    E(2,i+1)=E(2,i)-l*E(1,i)*E(2,i);
end
X=flip(data(311:345,12)');% 5.31  4.2
rate=flip(data(311:345,12)')%现阳性率
rate(isnan(rate))=0;
n=length(rate);
rt=0:1:n-1;
%a0=[100,10]; %初值
figure(1)
h1 = plot(rt,X/300000000,'*'); %画点
hold on;
a=E(1,:);
b=E(2,:);
h2 = plot(a,'r')
xlabel('日期');         %设置横坐标名
ylabel('感染人数');   %设置纵坐标名
legend([h1 h2],'3~5月感染人数','SIR模型迭代曲线','Location','NorthWest');
hold on
%%  预测
X=flip(data(255:345,12)');%311行后为第一题
rate=flip(data(255:345,12)')%现阳性率
rate(isnan(rate))=0;
n=length(rate);
rt=0:1:n-1;
figure(2)
h3 = plot(rt,X/300000000,'*'); %画点
hold on;
a=E(1,:);
b=E(2,:);
h4=plot(a,'r')
xlabel('日期');
ylabel('感染人数');
legend([h3 h4],'3~6月感染人数','SIR模型迭代曲线','Location','NorthWest');
hold on
%% 接种疫苗前
frame=importdata('usc.csv');
date_row=size(frame.data,1);
data=frame.data;
date=frame.textdata(:,1);
real_date=date(2:date_row+1,:);
E=zeros(3,150);
l=0.0018;    %日接触率 0.0018
m=0.01;   %日治愈率 0.01
E(1,1)=data(320,1)/300000000;
E(3,1)=28664448/300000000%43714928  33714928  28664448
E(2,1)=1-E(1,1)-E(3,1);

for i=1:150
    E(1,i+1)=E(1,i)+l*E(2,i)-m*E(1,i);
    E(2,i+1)=E(2,i)-l*E(1,i)*E(2,i);
    E(3,i+1)=1-E(1,i+1)- E(2,i+1);
end
X=data(320:486,1)';%80-482  3.1-7.1
rate=data(320:486,1)'%
rate(isnan(rate))=0;
n=length(rate);
rt=0:1:n-1;
figure(6)
h11 = plot(rt,X/300000000,'*'); %画点
hold on;
a=E(1,:);
b=E(2,:);
c=E(3,:);
t=1:151;
h1=plot(t,a,'r')%感染人数
%plot(t,b,'b')%健康人数
plot(t,c,'r')%移除者
%legend('i(t)','s(t)','r(t)')
hold on
%% 接种疫苗后
E=zeros(3,150);
l=0.0018;    %日接触率 0.0018
m=0.01;   %日治愈率 0.01
E(1,1)=data(320,1)/300000000;
E(3,1)=53714928/300000000%43714928  33714928  28664448
E(2,1)=1-E(1,1)-E(3,1);
for i=1:150
    E(1,i+1)=E(1,i)+l*E(2,i)-m*E(1,i);
    E(2,i+1)=E(2,i)-l*E(1,i)*E(2,i);
    E(3,i+1)=1-E(1,i+1)- E(2,i+1);
end
X=data(320:486,1)';%80-482  3.1-7.1
rate=data(320:486,1)'%
rate(isnan(rate))=0;
n=length(rate);
rt=0:1:n-1;
figure(6)
%h11 = plot(rt,X/300000000,'*'); %画点
hold on;
a=E(1,:);
b=E(2,:);
c=E(3,:);
t=1:151;
h2=plot(t,a,'b')%感染人数
%plot(t,b,'b')%健康人数
plot(t,c,'b')%移除者
%legend('i(t)','s(t)','r(t)')
hold on
xlabel('日期');         %设置横坐标名
ylabel('r(t)与i(t)');   %设置纵坐标名
legend([h1 h2 h11],'接种疫苗前','接种疫苗后','感染人数原始数据','Location','NorthWest');

logistic模型预测美国人口

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
%改进的指数增长模型
x=flip([324985536 322941312 320635168 318300992 315993728 313830976 311556864 309321664 306771520 304093952 301231200 298379904 295516608 292805312 290107936 287625184 284968960 282162400 279040000 275854016 272656992])
y=flip([0.006330017,0.007192424,0.007333235,0.007301613,0.006891455,0.007299188,0.007226135,0.008312845,0.008805068,0.009503504,0.009555925,0.00968912,0.009259723,0.009297836,0.008631901,0.009321099,0.009946612,0.011189794,0.011549529,0.011725443,0.012112401])
n=length(x);
t=0:1:n-1;
rk=zeros(1,n);
rk(1)=(-3*x(1)+4*x(2)-x(3))/2;
rk(n)=(x(n-2)-4*x(n-1)+3*x(n))/2;
for i=2:n-1
rk(i)=(x(i+1)-x(i-1))/2;
end
rk=rk./x;
p=polyfit(t,rk,2);
r0=p(1);
r1=p(2);
r2=p(3);
x0=x(1);
R=r0*t.^2+r1*t+r2;
X=x0*exp((r0*t.^3)/3+(r1*t.^2)/2+r2*t);
figure(1)
hold on;
xlabel('year');         %设置横坐标名
ylabel('rate');         %设置纵坐标名
grid on                 %网格线
plot(t,y,'r*')
figure(2)
hold on;
xlabel('year');         %设置横坐标名
ylabel('population');   %设置纵坐标名
grid on                 %网格线
plot(t,x,'r*',t,X)
figure(3)
hold on;
xlabel('year');         %设置横坐标名
ylabel('rate');         %设置纵坐标名
grid on                 %网格线
plot(t,y,'r*',t,R')
%2018
t1=t(21)+1;
x2018=x0*exp((r0*t1.^3)/3+(r1*t1.^2)/2+r2*t1)
y2018=r0*t1.^2+r1*t1+r2
%2019
t1=t(21)+2;
x2019=x0*exp((r0*t1.^3)/3+(r1*t1.^2)/2+r2*t1)
y2019=r0*t1.^2+r1*t1+r2

药物中毒急救建模

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
clc;
clear all;
syms x t;
f(t)=6*(exp(-0.1155*t)-exp(-0.1386*t));
h(t)=exp(-0.1386*t);
figure(1);
fplot(f,[0 25]);
hold on;
fplot(h,[0,25]);
grid on;
xlabel('时间t/h');
ylabel('药量');
legend('血液中的药量y/mg','胃肠道中的药量x/mg');
figure(2)
fplot(f,[0,25]);
hold on;
fplot(h,[0,25]);
f(t)=-(exp(-0.693*t)-exp(-0.1386*t))/4;
fplot(f,[0,25]);
xlabel('时间t/h');
ylabel('药量');
legend('血液中的药量y/mg','胃肠道中的药量x/mg','施救后血液中的药量y/mg');

热传导差分偏微分模型应用

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
clear;
close all;
clc;
pho=[300;862;74.2;1.18];
c=[1377;2100;1726;1005];
lamda=[0.082;0.37;0.045;0.028];
a=lamda./(pho.*c);

d=[0.6;6;3.6;5]*10^-3;

TT=273.15;
T_in=37;
T_out=75;
T_s=48.08;

xmin=0;
xmax=sum(d);

N=5400;
h=0.05*10^-3;
k=1;
r=k/h^2;
I=round((xmax-xmin)/h);

A=zeros(1,I);
B=zeros(1,I+1);
C=zeros(1,I);

N1=round(d(1)/h);
N2=round(d(2)/h);
N3=round(d(3)/h);
N4=round(d(4)/h);

for i=1:N1
    A(i)=-a(1)*r;
    B(i)=2+2*r*a(1);
    C(i)=-r*a(1);
end
for i=N1+1:N1+N2
    A(i)=-a(2)*r;
    B(i)=2+2*r*a(2);
    C(i)=-r*a(2);
end
for i=N1+N2+1:N1+N2+N3
    A(i)=-a(3)*r;
    B(i)=2+2*r*a(3);
    C(i)=-r*a(3);
end
for i=N1+N2+N3+1:N1+N2+N3+N4
    A(i)=-a(4)*r;
    B(i)=2+2*r*a(4);
    C(i)=-r*a(4);
end

T=zeros(I+1,N+1);
T(:,1)=(T_in+TT)*ones(I+1,1);

T_xt=xlsread('CUMCM-2018-Problem-A-Chinese-Appendix.xlsx');

h_min=110;
h_max=120;
delta_h=0.1;
H1=h_min:delta_h:h_max;
delta=zeros(1,length(H1));

for j=1:length(H1)
    h1=h_min+(j-1)*delta_h;
    k1=lamda(1);k2=lamda(2);k3=lamda(3);k4=lamda(4);
    x1=d(1);x2=d(1)+d(2);x3=d(1)+d(2)+d(3);x4=d(1)+d(2)+d(2)+d(4);
    t1=T_out+TT;t2=T_in+TT;t3=T_s+TT;

    h5=-((h1*k2*k3*k4*t1)/(k1*k2*k3*k4-h1*k1*k2*k3*x3-h1*k1*k2*k4*x2 ...
        -h1*k1*k3*k4*x1+h1*k1*k2*k3*x4+h1*k1*k2*k4*x3+h1*k1*k3*k4*x2+h1*k2*k3*k4*x1)-(h1*k2*k3*k4*t3)...
        /(k1*k2*k3*k4-h1*k1*k2*k3*x3-h1*k1*k2*k4*x2-h1*k1*k3*k4*x1+h1*k1*k2*k3*x4+h1*k1*k2*k4*x3+h1*k1*k3*k4*x2+h1*k2*k3*k4*x1))...
        /(t2/k1-t3/k1);

    AA=diag(B)+diag(A,1)+diag(C,-1);
    AA(1,1)=lamda(1)/h+h1;
    AA(1,2)=-lamda(1)/h;
    AA(I+1,I)=-lamda(4)/h;
    AA(I+1,I+1)=lamda(4)/h+h5;

    AA(N1+1,N1)=-lamda(1);
    AA(N1+1,N1+1)=lamda(1)+lamda(2);
    AA(N1+1,N1+2)=-lamda(2);

    AA(N1+N2+1,N1+N2)=-lamda(2);
    AA(N1+N2+1,N1+N2+1)=lamda(2)+lamda(3);
    AA(N1+N2+1,N1+N2+2)=-lamda(3);

    AA(N1+N2+N3+1,N1+N2+N3)=-lamda(3);
    AA(N1+N2+N3+1,N1+N2+N3+1)=lamda(3)+lamda(4);
    AA(N1+N2+N3+1,N1+N2+N3+2)=-lamda(4);

    for n=1:k:N
        D=zeros(I+1,1);
        D(1)=h1*(T_out+TT);
        D(I+1)=h5*(T_in+TT);
        for i=2:1:N1
            D(i)=r*a(1)*T(i-1,n)+(2-2*r*a(1))*T(i,n)+r*a(1)*T(i+1,n);
        end
        for i=N1+1:1:N1+N2
            D(i)=r*a(2)*T(i-1,n)+(2-2*r*a(2))*T(i,n)+r*a(2)*T(i+1,n);
        end
        for i=N1+N2+1:1:N1+N2+N3
            D(i)=r*a(3)*T(i-1,n)+(2-2*r*a(3))*T(i,n)+r*a(3)*T(i+1,n);
        end
        for i=N1+N2+N3+1:1:N1+N2+N3+N4
            D(i)=r*a(4)*T(i-1,n)+(2-2*r*a(4))*T(i,n)+r*a(4)*T(i+1,n);
        end
        D(N1+1)=0;
        D(N1+N2+1)=0;
        D(N1+N2+N3+1)=0;
        T(:,n+1)=AA\D;
    end
   delta(j)=sqrt(sum((T_xt(:,2)-T(end,:)'+TT).^2)/length(T_xt(:,1)));
end
%图二
figure(1);
mesh(0:k:N,1000*(0:h:sum(d)),(T-TT));
%图三
T_problem1=zeros(N+1,4);
T_problem1(:,1)=T(1,:)';
T_problem1(:,2)=T(N1+1,:)';
T_problem1(:,3)=T(N2+N1+1,:)';
T_problem1(:,4)=T(N3+N2+N1+1,:)';
T_problem1=T_problem1-TT;
figure(2);
plot(0:k:N,T_problem1(:,1)',0:k:N,T_problem1(:,2)',0:k:N,T_problem1(:,3)',0:k:N,T_problem1(:,4)',0:k:N,T_xt(:,2)');

python数据处理(写的很乱)

为了写第一个模型整合各种数据。。。有点乱,将就看吧。

1
2
3
4
5
6
7
8
#导入需要的数据库和文件
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from matplotlib.pyplot import MultipleLocator
odata=pd.read_csv(r'us_state_vaccinations.csv')
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
r_hex = '#dc2624'     # red,       RGB = 220,38,36
dt_hex = '#2b4750'    # dark teal, RGB = 43,71,80
tl_hex = '#45a0a2'    # teal,      RGB = 69,160,162
r1_hex = '#e87a59'    # red,       RGB = 232,122,89
tl1_hex = '#7dcaa9'   # teal,      RGB = 125,202,169
g_hex = '#649E7D'     # green,     RGB = 100,158,125
o_hex = '#dc8018'     # orange,    RGB = 220,128,24
tn_hex = '#C89F91'    # tan,       RGB = 200,159,145
g50_hex = '#6c6d6c'   # grey-50,   RGB = 108,109,108
bg_hex = '#4f6268'    # blue grey, RGB = 79,98,104
g25_hex = '#c7cccf'   # grey-25,   RGB = 199,204,207
1
odata

datelocationtotal_vaccinationstotal_distributedpeople_vaccinatedpeople_fully_vaccinated_per_hundredtotal_vaccinations_per_hundredpeople_fully_vaccinatedpeople_vaccinated_per_hundreddistributed_per_hundreddaily_vaccinations_rawdaily_vaccinationsdaily_vaccinations_per_millionshare_doses_used
02021-01-12Alabama78134.0377025.070861.00.151.597270.01.457.69NaNNaNNaN0.207
12021-01-13Alabama84040.0378975.074792.00.191.719245.01.537.735906.05906.01205.00.222
22021-01-14Alabama92300.0435350.080480.0NaN1.88NaN1.648.888260.07083.01445.00.212
32021-01-15Alabama100567.0444650.086956.00.282.0513488.01.779.078267.07478.01525.00.226
42021-01-16AlabamaNaNNaNNaNNaNNaNNaNNaNNaN7557.07498.01529.0NaN
.............................................
113282021-06-30Wyoming421749.0516025.0226911.034.3872.87198958.039.2189.1655.0913.01578.00.817
113292021-07-01Wyoming423238.0516325.0227741.034.5173.13199743.039.3589.211489.01113.01923.00.820
113302021-07-02Wyoming424025.0516865.0228162.034.5973.26200184.039.4289.31787.0847.01463.00.820
113312021-07-03Wyoming431008.0517365.0230914.035.3474.47204522.039.9089.396983.01680.02903.00.833
113322021-07-04Wyoming431101.0517365.0230993.035.3574.49204598.039.9189.3993.01682.02906.00.833

11333 rows × 14 columns

1
2
states = list(set(odata['location']))
len(states)
65
1
2
3
date = list(set(odata['date']))
date.sort()
date
1
date[0]
'2020-12-20'
1
2
US = odata.loc[odata['date'] == '2021-01-12']
US

datelocationtotal_vaccinationstotal_distributedpeople_vaccinatedpeople_fully_vaccinated_per_hundredtotal_vaccinations_per_hundredpeople_fully_vaccinatedpeople_vaccinated_per_hundreddistributed_per_hundreddaily_vaccinations_rawdaily_vaccinationsdaily_vaccinations_per_millionshare_doses_used
02021-01-12Alabama78134.0377025.070861.00.151.597270.01.457.69NaNNaNNaN0.207
1742021-01-12Alaska35838.0141600.022486.00.744.905400.03.0719.36NaNNaNNaN0.253
3482021-01-12American Samoa2124.010650.0842.00.473.81260.01.5119.12NaNNaNNaN0.199
5222021-01-12Arizona141355.0563025.095141.00.111.948343.01.317.74NaNNaNNaN0.251
6962021-01-12Arkansas40879.0274400.039357.00.001.358.01.309.09NaNNaNNaN0.149
.............................................
104632021-01-12Virginia190607.0797150.0NaNNaN2.23NaNNaN9.34NaNNaNNaN0.239
106372021-01-12Washington195567.0567725.0162105.00.232.5717689.02.137.46NaNNaNNaN0.344
108112021-01-12West Virginia103330.0160975.0NaNNaN5.77NaNNaN8.98NaNNaNNaN0.642
109852021-01-12Wisconsin137253.0429500.0125895.00.192.3611343.02.167.38NaNNaNNaN0.320
111592021-01-12Wyoming16467.047800.013577.00.372.852116.02.358.26NaNNaNNaN0.344

65 rows × 14 columns

1
US['people_vaccinated'].sum()
15746663.0
1
data=[]
1
2
3
4
for i in date:
    temp = odata.loc[odata['date'] == i]
    data.append(temp['people_vaccinated'].sum())
data
1
2
dataframe=pd.DataFrame(data=data, index=date, columns=['vaccinations'], dtype=None, copy=False)
dataframe

vaccinations
2020-12-200.0
2020-12-210.0
2020-12-220.0
2020-12-230.0
2020-12-240.0
......
2021-06-30366017545.0
2021-07-01367355455.0
2021-07-02367983174.0
2021-07-03368905977.0
2021-07-04369524458.0

197 rows × 1 columns

1
2
3
4
5
dataframe.dropna(subset=['vaccinations'],inplace=True)
dataframe.columns = ['vaccinations']
dataframe.drop(dataframe[dataframe['vaccinations']<0.01].index)
vus = dataframe
vus

vaccinations
2020-12-200.0
2020-12-210.0
2020-12-220.0
2020-12-230.0
2020-12-240.0
......
2021-06-30366017545.0
2021-07-01367355455.0
2021-07-02367983174.0
2021-07-03368905977.0
2021-07-04369524458.0

197 rows × 1 columns

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
fig = plt.figure( figsize=(16,6), dpi=100)
ax = fig.add_subplot(1,1,1)
x = dataframe.index
y = dataframe['vaccinations']
ax.plot( x, y, color=dt_hex, linewidth=2, linestyle='-' )
ax.set_title('接种疫苗人数(/千万)',fontdict={
      'color':'black',
      'size':24
})
ax.set_xticks( range(0,len(x),30))
[<matplotlib.axis.XTick at 0x208ab850c18>,
 <matplotlib.axis.XTick at 0x208ab850be0>,
 <matplotlib.axis.XTick at 0x208ab8426a0>,
 <matplotlib.axis.XTick at 0x208ad89a588>,
 <matplotlib.axis.XTick at 0x208ad89aa20>,
 <matplotlib.axis.XTick at 0x208ad89aeb8>,
 <matplotlib.axis.XTick at 0x208ad89a978>]

png

1
cdata=pd.read_csv(r'DXYArea.csv')
1
cdata

continentNamecontinentEnglishNamecountryNamecountryEnglishNameprovinceNameprovinceEnglishNameprovince_zipCodeprovince_confirmedCountprovince_suspectedCountprovince_curedCountprovince_deadCountupdateTimecityNamecityEnglishNamecity_zipCodecity_confirmedCountcity_suspectedCountcity_curedCountcity_deadCount
0北美洲North America美国United States of America美国United States of America971002337185380.0290968166055262021-07-05 19:13:09NaNNaNNaNNaNNaNNaNNaN
1欧洲Europe法国France法国France96100259216960.03533701111902021-07-05 19:12:06NaNNaNNaNNaNNaNNaNNaN
2南美洲South America巴西Brazil巴西Brazil973003187698080.0170828765244752021-07-05 19:12:06NaNNaNNaNNaNNaNNaNNaN
3欧洲Europe瑞典Sweden瑞典Sweden96200510908800.04971146312021-07-05 19:12:06NaNNaNNaNNaNNaNNaNNaN
4欧洲Europe俄罗斯Russia俄罗斯Russia96400656352940.050834411385792021-07-05 19:12:06NaNNaNNaNNaNNaNNaNNaN
............................................................
554367亚洲Asia中国China辽宁省Liaoning21000001.0002020-01-22 03:28:10NaNNaNNaNNaNNaNNaNNaN
554368亚洲Asia中国China台湾Taiwan71000010.0002020-01-22 03:28:10NaNNaNNaNNaNNaNNaNNaN
554369亚洲Asia中国Hongkong香港Hongkong8100000117.0002020-01-22 03:28:10NaNNaNNaNNaNNaNNaNNaN
554370亚洲Asia中国China黑龙江省Heilongjiang23000001.0002020-01-22 03:28:10NaNNaNNaNNaNNaNNaNNaN
554371亚洲Asia中国China湖南省Hunan43000010.0002020-01-22 03:28:10NaNNaNNaNNaNNaNNaNNaN

554372 rows × 19 columns

1
2
3
cus = cdata.loc[cdata['countryName'] == '美国']
comfirm=cus.copy()
cus

continentNamecontinentEnglishNamecountryNamecountryEnglishNameprovinceNameprovinceEnglishNameprovince_zipCodeprovince_confirmedCountprovince_suspectedCountprovince_curedCountprovince_deadCountupdateTimecityNamecityEnglishNamecity_zipCodecity_confirmedCountcity_suspectedCountcity_curedCountcity_deadCount
0北美洲North America美国United States of America美国United States of America971002337185380.0290968166055262021-07-05 19:13:09NaNNaNNaNNaNNaNNaNNaN
106北美洲North America美国United States of America美国United States of America971002337169330.0290968166055262021-07-05 11:05:16NaNNaNNaNNaNNaNNaNNaN
308北美洲North America美国United States of America美国United States of America971002337169330.0290968166055262021-07-05 10:01:19NaNNaNNaNNaNNaNNaNNaN
437北美洲North America美国United States of America美国United States of America971002337169330.0290968166055262021-07-05 09:39:02NaNNaNNaNNaNNaNNaNNaN
728北美洲North America美国United States of America美国United States of America971002337149280.0290874216055242021-07-04 21:41:13NaNNaNNaNNaNNaNNaNNaN
............................................................
541769北美洲North America美国United States of America美国United States of America97100290.0002020-02-03 09:28:34NaNNaNNaNNaNNaNNaNNaN
543505北美洲North America美国United States of America美国United States of America97100280.0002020-02-02 07:41:43NaNNaNNaNNaNNaNNaNNaN
545557北美洲North America美国United States of America美国United States of America97100260.0002020-02-01 02:48:13NaNNaNNaNNaNNaNNaNNaN
547090NaNNaN美国United States of America美国United States of America97100260.0002020-01-31 07:17:36NaNNaNNaNNaNNaNNaNNaN
550409NaNNaN美国United States of America美国United States of America97100250.0002020-01-27 17:20:43NaNNaNNaNNaNNaNNaNNaN

3241 rows × 19 columns

1
2
3
4
5
6
7
8
cus['updateTime'] = pd.to_datetime(cus.updateTime,format="%Y-%m-%d",errors='coerce').dt.date
cus.drop_duplicates(subset=['provinceName', 'updateTime'], keep='first', inplace=True)
cus.drop(['provinceName','continentName','continentEnglishName','countryEnglishName','cityName','province_deadCount','province_suspectedCount','city_deadCount','city_curedCount','city_suspectedCount','city_confirmedCount','province_confirmedCount','countryName','provinceEnglishName','province_zipCode','cityEnglishName','city_zipCode'],axis=1,inplace=True)
cus.dropna(subset=['province_curedCount'],inplace=True)
cus = cus.drop(cus[cus['province_curedCount']<0.01].index)
#cus = cus.drop(cus[cus['updateTime']<0.01].index)
cus = cus.sort_values(by='updateTime', ascending=True)
cus

province_curedCountupdateTime
52005432020-02-12
51792432020-02-13
51565032020-02-14
51456632020-02-15
51173832020-02-16
.........
3425290266882021-07-01
2131290520872021-07-02
1499290728812021-07-03
728290874212021-07-04
0290968162021-07-05

477 rows × 2 columns

1
cus['province_curedCount']
520054           3
517924           3
515650           3
514566           3
511738           3
            ...
3425      29026688
2131      29052087
1499      29072881
728       29087421
0         29096816
Name: province_curedCount, Length: 477, dtype: int64
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
#cus.set_index('updateTime',inplace=True)
#cus.index.name = None
temp = cus['updateTime'].copy()
cout=0
temp_list = []
for i in temp:
    temp_list.append(str(i))
    cout+=1
cus["updateTime"]=temp_list
cus.set_index('updateTime',inplace=True)
cus

province_curedCount
updateTime
2020-02-123
2020-02-133
2020-02-143
2020-02-153
2020-02-163
......
2021-07-0129026688
2021-07-0229052087
2021-07-0329072881
2021-07-0429087421
2021-07-0529096816

477 rows × 1 columns

1
2
3
4
5
6
7
8
9
fig, axes = plt.subplots(1,1,figsize=(16, 4))
x=cus.index
y=cus.values
plot=axes.plot(x,y,color=dt_hex,linewidth=2,linestyle='-',label='治愈')
axes.set_xticks(range(0,len(x),40))
plt.xlabel('日期',fontsize=10)
plt.ylabel('人数',fontsize=10)
axes.legend(loc=0,frameon=True)
plt.show()

png

1
2
3
v_cus = cus.loc[cus.index > '2021-03-01']
v_cus.columns = ['curedCount']
v_cus

curedCount
updateTime
2021-03-0219817532
2021-03-0319905322
2021-03-0419997983
2021-03-0520093442
2021-03-0620183329
......
2021-07-0129026688
2021-07-0229052087
2021-07-0329072881
2021-07-0429087421
2021-07-0529096816

106 rows × 1 columns

1
2
3
v_vus=vus.loc[vus.index > '2021-03-01']
v_vus.index.name = "updateTime"
v_vus

vaccinations
updateTime
2021-03-02105774893.0
2021-03-03108010927.0
2021-03-04110417023.0
2021-03-05113492161.0
2021-03-06117171344.0
......
2021-06-30366017545.0
2021-07-01367355455.0
2021-07-02367983174.0
2021-07-03368905977.0
2021-07-04369524458.0

125 rows × 1 columns

1
2
3
4
result = pd.merge( v_cus, v_vus, how='left',on='updateTime')
result.dropna(subset=['curedCount'],inplace=True)
result.dropna(subset=['vaccinations'],inplace=True)
result

curedCountvaccinations
updateTime
2021-03-0219817532105774893.0
2021-03-0319905322108010927.0
2021-03-0419997983110417023.0
2021-03-0520093442113492161.0
2021-03-0620183329117171344.0
.........
2021-06-3029007495366017545.0
2021-07-0129026688367355455.0
2021-07-0229052087367983174.0
2021-07-0329072881368905977.0
2021-07-0429087421369524458.0

105 rows × 2 columns

1
#result.to_csv("cvus.csv")
1
2
3
4
pusdata=pd.read_csv(r'美国covid19疫情数据l-history改.csv')
pusdata['date'] = pd.to_datetime(pusdata.date,format="%Y-%m-%d",errors='coerce').dt.date
pusdata = pusdata.sort_values(by='date', ascending=True)
pusdata

datedeathdeathIncreaseinIcuCumulativeinIcuCurrentlyhospitalizedIncreasehospitalizedCurrentlyhospitalizedCumulativenegativenegativeIncreaseonVentilatorCumulativeonVentilatorCurrentlypositivepositiveIncreaseUnnamed: 14statestotalTestResultstotalTestResultsIncrease
4192020-01-13NaN0NaNNaN0NaNNaNNaN0NaNNaNNaN0NaN100
4182020-01-14NaN0NaNNaN0NaNNaNNaN0NaNNaN0.00NaN100
4172020-01-15NaN0NaNNaN0NaNNaNNaN0NaNNaN0.00NaN100
4162020-01-16NaN0NaNNaN0NaNNaNNaN0NaNNaN0.00NaN100
4152020-01-17NaN0NaNNaN0NaNNaNNaN0NaNNaN0.00NaN100
.........................................................
42021-03-03508665.0244945214.09359.0217245462.0873073.073857281.02670014260.03094.028520365.0668360.002349563578886711406795
32021-03-04510408.0174345293.08970.0153044172.0874603.074035238.01779574267.02973.028585852.0654870.002296563594796551590984
22021-03-05512629.0222145373.08634.0278142541.0877384.074307155.02719174275.02889.028654639.0687870.002406563612240721744417
12021-03-06514309.0168045453.08409.050341401.0877887.074450990.01438354280.02811.028714654.0600150.002094563626550641430992
02021-03-07515151.084245475.08134.072640199.0878613.074582825.01318354281.02802.028756489.0418350.001457563638251231170059

420 rows × 18 columns

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
temp = pusdata['date'].copy()
cout=0
temp_list = []
for i in temp:
    temp_list.append(str(i))
    cout+=1
pusdata["date"]=temp_list
pusdata.set_index('date',inplace=True)
pusdata=pusdata[['positive']]
pusdata.index.name = "updateTime"
pusdata

positive
updateTime
2020-01-13NaN
2020-01-140.0
2020-01-150.0
2020-01-160.0
2020-01-170.0
......
2021-03-0328520365.0
2021-03-0428585852.0
2021-03-0528654639.0
2021-03-0628714654.0
2021-03-0728756489.0

420 rows × 1 columns

1
#pd.merge( result,pusdata, how='left',on='updateTime').dropna(subset=['positive'],inplace=True)
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
#confirm
comfirm['updateTime'] = pd.to_datetime(comfirm.updateTime,format="%Y-%m-%d",errors='coerce').dt.date
comfirm.drop_duplicates(subset=['provinceName', 'updateTime'], keep='first', inplace=True)
comfirm.drop(['provinceName','continentName','continentEnglishName','countryEnglishName','cityName','province_deadCount','province_suspectedCount','city_deadCount','city_curedCount','city_suspectedCount','city_confirmedCount','province_curedCount','countryName','provinceEnglishName','province_zipCode','cityEnglishName','city_zipCode'],axis=1,inplace=True)
comfirm.dropna(subset=['province_confirmedCount'],inplace=True)
comfirm = comfirm.drop(comfirm[comfirm['province_confirmedCount']<0.01].index)
comfirm = comfirm.sort_values(by='updateTime', ascending=True)
temp = comfirm['updateTime'].copy()
cout=0
temp_list = []
for i in temp:
    temp_list.append(str(i))
    cout+=1
comfirm["updateTime"]=temp_list
comfirm.set_index('updateTime',inplace=True)
comfirm.columns = ['confirmedCount']
comfirm

confirmedCount
updateTime
2020-01-275
2020-01-316
2020-02-016
2020-02-028
2020-02-039
......
2021-07-0133665047
2021-07-0233679489
2021-07-0333709176
2021-07-0433714928
2021-07-0533718538

486 rows × 1 columns

1
2
3
result = pd.merge( result,comfirm, how='left',on='updateTime')
result.dropna(subset=['confirmedCount'],inplace=True)
result

curedCountvaccinationsconfirmedCount
updateTime
2021-03-0219817532105774893.028664448
2021-03-0319905322108010927.028719624
2021-03-0419997983110417023.028771556
2021-03-0520093442113492161.028827140
2021-03-0620183329117171344.028894787
............
2021-06-3029007495366017545.033653426
2021-07-0129026688367355455.033665047
2021-07-0229052087367983174.033679489
2021-07-0329072881368905977.033709176
2021-07-0429087421369524458.033714928

105 rows × 3 columns

1
#result.to_csv("cvus.csv")

完整文档详见:博客相关资源-常微分偏微分建模练习