当前位置:网站首页>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 '''
边栏推荐
- [server data recovery] a case of RAID data recovery of a brand StorageWorks server
- Write a ten thousand word long article "CAS spin lock" to send Jay's new album to the top of the hot list
- Typescript release 4.8 beta
- Annexb and avcc are two methods of data segmentation in decoding
- Starting from 1.5, build a microservice framework link tracking traceid
- Create lib Library in keil and use lib Library
- A need to review all the knowledge, H5 form is blocked by the keyboard, event agent, event delegation
- LeetCode3_ Longest substring without duplicate characters
- Getting started with webgl (3)
- 【数字IC验证快速入门】22、SystemVerilog项目实践之AHB-SRAMC(2)(AMBA总线介绍)
猜你喜欢
【数字IC验证快速入门】29、SystemVerilog项目实践之AHB-SRAMC(9)(AHB-SRAMC SVTB Overview)
TypeScript 发布 4.8 beta 版本
[quick start of Digital IC Verification] 23. AHB sramc of SystemVerilog project practice (3) (basic points of AHB protocol)
Unity之ASE实现卡通火焰
Asynchronous application of generator function
Window环境下配置Mongodb数据库
webgl_ Graphic transformation (rotation, translation, zoom)
2022全开源企业发卡网修复短网址等BUG_2022企业级多商户发卡平台源码
【数字IC验证快速入门】22、SystemVerilog项目实践之AHB-SRAMC(2)(AMBA总线介绍)
微信小程序 01
随机推荐
Jacobo code coverage
HW初级流量监控,到底该怎么做
【數據挖掘】視覺模式挖掘:Hog特征+餘弦相似度/k-means聚類
[server data recovery] a case of RAID data recovery of a brand StorageWorks server
Ida Pro reverse tool finds the IP and port of the socket server
LeetCode1_ Sum of two numbers
[quickstart to Digital IC Validation] 20. Basic syntax for system verilog Learning 7 (Coverage Driven... Including practical exercises)
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)
Pit avoidance: description of null values in in and not in SQL
Virtual memory, physical memory /ram what
15. Using the text editing tool VIM
Streaming end, server end, player end
Steps to create P8 certificate and warehousing account
How to understand that binary complement represents negative numbers
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
Using eating in cocos Creator
【跟着江科大学Stm32】STM32F103C8T6_PWM控制直流电机_代码
Connecting FTP server tutorial
【Markdown语法高级】让你的博客更精彩(四:设置字体样式以及颜色对照表)