当前位置:网站首页>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 '''
边栏推荐
- Async and await
- 2. 堆排序『较难理解的排序』
- 2. Heap sort "hard to understand sort"
- 写一篇万字长文《CAS自旋锁》送杰伦的新专辑登顶热榜
- 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
- 【数字IC验证快速入门】22、SystemVerilog项目实践之AHB-SRAMC(2)(AMBA总线介绍)
- Detailed explanation of Cocos creator 2.4.0 rendering process
- 如何在opensea批量发布NFT(Rinkeby测试网)
- Android -- jetpack: the difference between livedata setValue and postvalue
- The rebound problem of using Scrollview in cocos Creator
猜你喜欢
MongoD管理数据库的方法介绍
![[deep learning] image hyperspectral experiment: srcnn/fsrcnn](/img/84/114fc8f0875b82cc824e6400bcb06f.png)
[deep learning] image hyperspectral experiment: srcnn/fsrcnn

Streaming end, server end, player end

webgl_ Enter the three-dimensional world (1)

【深度学习】图像超分实验:SRCNN/FSRCNN

Do you know the relationship between the most important indicators of two strong wind control and the quality of the customer base

OpenGL's distinction and understanding of VAO, VBO and EBO

【目标检测】YOLOv5跑通VOC2007数据集

【微信小程序】Chapter(5):微信小程序基础API接口
![[quick start of Digital IC Verification] 20. Basic grammar of SystemVerilog learning 7 (coverage driven... Including practical exercises)](/img/d3/cab8a1cba3c8d8107ce4a95f328d36.png)
[quick start of Digital IC Verification] 20. Basic grammar of SystemVerilog learning 7 (coverage driven... Including practical exercises)
随机推荐
Briefly describe the working principle of kept
Matlab experience summary
Yunxiaoduo software internal test distribution test platform description document
【数字IC验证快速入门】19、SystemVerilog学习之基本语法6(线程内部通信...内含实践练习)
[quickstart to Digital IC Validation] 20. Basic syntax for system verilog Learning 7 (Coverage Driven... Including practical exercises)
15. Using the text editing tool VIM
Super simple and fully automated generation super signature system (cloud Xiaoduo minclouds.com cloud service instance), free application in-house test app distribution and hosting platform, maintenan
[deep learning] image hyperspectral experiment: srcnn/fsrcnn
[quick start of Digital IC Verification] 18. Basic grammar of SystemVerilog learning 5 (concurrent threads... Including practical exercises)
Wechat applet 01
【微信小程序】Chapter(5):微信小程序基础API接口
一大波开源小抄来袭
避坑:Sql中 in 和not in中有null值的情况说明
Getting started with webgl (4)
[deep learning] semantic segmentation experiment: UNET network /msrc2 dataset
HW primary flow monitoring, what should we do
[quick start of Digital IC Verification] 23. AHB sramc of SystemVerilog project practice (3) (basic points of AHB protocol)
Basic knowledge sorting of mongodb database
Monthly observation of internet medical field in May 2022
LeetCode2_ Add two numbers