当前位置:网站首页>numpy--疫情数据分析案例
numpy--疫情数据分析案例
2022-07-07 13:26:00 【madkeyboard】
文章目录
前期准备
下载数据文件,从数据文件中读取数据分组进行存储。
数据文件地址:https://mofanpy.com/static/files/covid19_day_wise.csv
with open("covid19_day_wise.csv", "r", encoding="utf-8") as f:
data = f.readlines() # 打开文件读取数据
covid = {
# 定义一个对象存储日期、数据和标题
"date": [], # 日期
"data": [], # 数据
"header": [h for h in data[0].strip().split(",") [1:]] # 标题
}
for row in data[1:]: # 分组存放数据
split_row = row.strip().split(",")
covid["date"].append(split_row[0])
covid["data"].append([float(n) for n in split_row[1:]])
数据分析
获取 2020 年 2 月 3 日的所有数据
target = covid["date"].index("2020-02-03") # 找到目标日期的下标
data = np.array(covid["data"])
for header, number in zip(covid["header"],data[target]):
print(header," : ",number)
2020 年 1 月 24 日之前的累积确诊病例有多少个?
target = covid["date"].index("2020-01-24") # 找到目标日期的下标
confirm_idx = covid["header"].index("Confirmed") # 获取确诊标题的下标
data = np.array(covid["data"])
print("2020 年 1 月 24 日之前的累积确诊病例有 %d 个" % data[target,confirm_idx]) # 这里要注统计的数据不包括1月14
# 2020 年 1 月 24 日之前的累积确诊病例有 941 个
从 1 月 25 日到 7 月 22 日,一共增长了多少确诊病例?
target_idx1 = covid["date"].index("2020-01-25")
target_idx2 = covid["date"].index("2020-07-22")
new_cases_idx = covid['header'].index("New cases")
data = np.array(covid["data"])
new_cases = data[target_idx1 + 1: target_idx2 + 1,new_cases_idx]
print("总共增长:",new_cases.sum())
# 总共增长: 15247309.0
每天新增确诊数和新恢复数的比例?平均比例,标准差各是多少?
new_cases_idx = covid['header'].index("New cases")
new_recovered_idx = covid['header'].index("New recovered")
data = np.array(covid["data"])
not_zero_mask = data[:, new_recovered_idx] != 0 # 筛选出除数为0,返回false
ratio = data[not_zero_mask,new_cases_idx] / data[not_zero_mask,new_recovered_idx] # 分别拿到新增确证数和新的恢复数,然后依次相除
print("比例:",ratio[:5]) # 前5组比例
print("平均比例:",ratio.mean(),"\n标准差:",ratio.std())
''' 比例: [ 49.5 47.83333333 164.33333333 52.61538462 89.88888889] 平均比例: 7.049556348053241 标准差: 19.094025710450307 '''
边栏推荐
- [deep learning] image hyperspectral experiment: srcnn/fsrcnn
- Getting started with webgl (3)
- Unity's ASE achieves full screen sand blowing effect
- Introduction of mongod management database method
- webgl_ Enter the three-dimensional world (2)
- 一大波开源小抄来袭
- Super signature principle (fully automated super signature) [Yun Xiaoduo]
- 【数字IC验证快速入门】29、SystemVerilog项目实践之AHB-SRAMC(9)(AHB-SRAMC SVTB Overview)
- 【深度学习】语义分割实验:Unet网络/MSRC2数据集
- Wechat applet 01
猜你喜欢
Steps to create P8 certificate and warehousing account
【数字IC验证快速入门】25、SystemVerilog项目实践之AHB-SRAMC(5)(AHB 重点回顾,要点提炼)
[quick start of Digital IC Verification] 29. Ahb-sramc (9) (ahb-sramc svtb overview) of SystemVerilog project practice
15. Using the text editing tool VIM
[make a boat diary] [shapr3d STL format to gcode]
[quick start of Digital IC Verification] 18. Basic grammar of SystemVerilog learning 5 (concurrent threads... Including practical exercises)
[quick start for Digital IC Validation] 26. Ahb - sramc (6) for system verilog project practice (Basic Points of APB Protocol)
如何在opensea批量发布NFT(Rinkeby测试网)
LeetCode2_ Add two numbers
The bank needs to build the middle office capability of the intelligent customer service module to drive the upgrade of the whole scene intelligent customer service
随机推荐
How to create Apple Developer personal account P8 certificate
简述keepalived工作原理
Oracle控制文件丢失恢复归档模式方法
How to build your own super signature system (yunxiaoduo)?
The "go to definition" in VS2010 does not respond or prompts the solution of "symbol not found"
Syntax of generator function (state machine)
Please supervise the 2022 plan
HW初级流量监控,到底该怎么做
Briefly describe the working principle of kept
Yunxiaoduo software internal test distribution test platform description document
【數據挖掘】視覺模式挖掘:Hog特征+餘弦相似度/k-means聚類
Wechat applet 01
Nacos一致性协议 CP/AP/JRaft/Distro协议
[quick start of Digital IC Verification] 18. Basic grammar of SystemVerilog learning 5 (concurrent threads... Including practical exercises)
[quick start of Digital IC Verification] 23. AHB sramc of SystemVerilog project practice (3) (basic points of AHB protocol)
Write sequence frame animation with shader
Vertex shader to slice shader procedure, varying variable
【數字IC驗證快速入門】20、SystemVerilog學習之基本語法7(覆蓋率驅動...內含實踐練習)
XMIND frame drawing tool
jacoco代码覆盖率