当前位置:网站首页>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 '''
边栏推荐
- Yunxiaoduo software internal test distribution test platform description document
- Pat grade a 1103 integer factorizatio
- leetcode 241. Different ways to add parentheses design priority for operational expressions (medium)
- 【兰州大学】考研初试复试资料分享
- Actually changed from 408 to self proposition! 211 North China Electric Power University (Beijing)
- [quick start of Digital IC Verification] 29. Ahb-sramc (9) (ahb-sramc svtb overview) of SystemVerilog project practice
- Jacobo code coverage
- Do you know the relationship between the most important indicators of two strong wind control and the quality of the customer base
- 【数字IC验证快速入门】22、SystemVerilog项目实践之AHB-SRAMC(2)(AMBA总线介绍)
- 【数字IC验证快速入门】19、SystemVerilog学习之基本语法6(线程内部通信...内含实践练习)
猜你喜欢

What is Base64?

Virtual memory, physical memory /ram what

Monthly observation of internet medical field in May 2022

The download button and debug button in keil are grayed out

【数字IC验证快速入门】19、SystemVerilog学习之基本语法6(线程内部通信...内含实践练习)

【目标检测】YOLOv5跑通VOC2007数据集
![[quick start of Digital IC Verification] 26. Ahb-sramc of SystemVerilog project practice (6) (basic points of APB protocol)](/img/7e/188e57ee026200478a6f61eb507c92.png)
[quick start of Digital IC Verification] 26. Ahb-sramc of SystemVerilog project practice (6) (basic points of APB protocol)
![[deep learning] semantic segmentation experiment: UNET network /msrc2 dataset](/img/69/9dadeb92f8d6299250a894690c2845.png)
[deep learning] semantic segmentation experiment: UNET network /msrc2 dataset

【微信小程序】Chapter(5):微信小程序基础API接口

Write sequence frame animation with shader
随机推荐
Iterator and for of.. loop
简述keepalived工作原理
大表delete删数据导致数据库异常解决
Annexb and avcc are two methods of data segmentation in decoding
[quick start of Digital IC Verification] 18. Basic grammar of SystemVerilog learning 5 (concurrent threads... Including practical exercises)
居然从408改考自命题!211华北电力大学(北京)
【数字IC验证快速入门】19、SystemVerilog学习之基本语法6(线程内部通信...内含实践练习)
Virtual memory, physical memory /ram what
Pit avoidance: description of null values in in and not in SQL
2022 all open source enterprise card issuing network repair short website and other bugs_ 2022 enterprise level multi merchant card issuing platform source code
[quick start for Digital IC Validation] 26. Ahb - sramc (6) for system verilog project practice (Basic Points of APB Protocol)
Keil5 does not support online simulation of STM32 F0 series
【搞船日记】【Shapr3D的STL格式转Gcode】
Async and await
OpenGL common functions
Unity之ASE实现卡通火焰
Database exception resolution caused by large table delete data deletion
【数字IC验证快速入门】20、SystemVerilog学习之基本语法7(覆盖率驱动...内含实践练习)
The difference between full-time graduate students and part-time graduate students!
LeetCode2_ Add two numbers