当前位置:网站首页>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 '''
边栏推荐
- Introduction of mongod management database method
- Jacobo code coverage
- 【数字IC验证快速入门】29、SystemVerilog项目实践之AHB-SRAMC(9)(AHB-SRAMC SVTB Overview)
- [quick start of Digital IC Verification] 25. AHB sramc of SystemVerilog project practice (5) (AHB key review, key points refining)
- After UE4 is packaged, mesh has no material problem
- Getting started with webgl (3)
- Unity之ASE实现全屏风沙效果
- 微信小程序 01
- The rebound problem of using Scrollview in cocos Creator
- Write sequence frame animation with shader
猜你喜欢
15. Using the text editing tool VIM
[quick start of Digital IC Verification] 26. Ahb-sramc of SystemVerilog project practice (6) (basic points of APB protocol)
有一头母牛,它每年年初生一头小母牛。每头小母牛从第四个年头开始,每年年初也生一头小母牛。请编程实现在第n年的时候,共有多少头母牛?
[deep learning] image hyperspectral experiment: srcnn/fsrcnn
[quick start of Digital IC Verification] 25. AHB sramc of SystemVerilog project practice (5) (AHB key review, key points refining)
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
Introduction of mongod management database method
[Data Mining] Visual Pattern Mining: Hog Feature + cosinus Similarity / K - means Clustering
[make a boat diary] [shapr3d STL format to gcode]
Use of SVN
随机推荐
Oracle控制文件丢失恢复归档模式方法
How to deploy the super signature distribution platform system?
【數據挖掘】視覺模式挖掘:Hog特征+餘弦相似度/k-means聚類
webgl_ Enter the three-dimensional world (2)
【Markdown语法高级】让你的博客更精彩(四:设置字体样式以及颜色对照表)
unnamed prototyped parameters not allowed when body is present
Database exception resolution caused by large table delete data deletion
大表delete删数据导致数据库异常解决
Virtual memory, physical memory /ram what
银行需要搭建智能客服模块的中台能力,驱动全场景智能客服务升级
OpenGL common functions
Share the technical details of super signature system construction
2022全开源企业发卡网修复短网址等BUG_2022企业级多商户发卡平台源码
#HPDC智能基座人才发展峰会随笔
Detailed explanation of Cocos creator 2.4.0 rendering process
[quick start of Digital IC Verification] 25. AHB sramc of SystemVerilog project practice (5) (AHB key review, key points refining)
[quick start of Digital IC Verification] 22. Ahb-sramc of SystemVerilog project practice (2) (Introduction to AMBA bus)
Asynchronous application of generator function
2.Golang基础知识
Keil5 does not support online simulation of STM32 F0 series