当前位置: 首页 > news >正文

四会市网站建设百度seo排名规则

四会市网站建设,百度seo排名规则,seo是什么学校,做网站特别简单的软件Python NumPy 数据分析:处理复杂数据的高效方法 文章目录 Python NumPy 数据分析:处理复杂数据的高效方法一 数据来源二 获取指定日期数据三 获取指定行列数据四 求和计算五 比例计算六 平均值和标准差七 完整代码示例八 源码地址 本文详细介绍了如何使用…

Python NumPy 数据分析:处理复杂数据的高效方法

文章目录

  • Python NumPy 数据分析:处理复杂数据的高效方法
      • 一 数据来源
      • 二 获取指定日期数据
      • 三 获取指定行列数据
      • 四 求和计算
      • 五 比例计算
      • 六 平均值和标准差
      • 七 完整代码示例
      • 八 源码地址

本文详细介绍了如何使用 Python 和 NumPy 对复杂数据进行高效的数据分析。通过从 Kaggle 获取的公开数据集,演示了如何读取 CSV 文件、提取特定日期和字段的数据,并进行数据的统计与分析。本文展示了使用 NumPy 进行数据操作的便捷方式,如通过索引获取指定行列数据,计算累计数值和新增长的总数,还讲解了如何计算比率、平均值、标准差等关键统计数据。文章还包括完整的代码示例,帮助读者轻松上手进行复杂数据的分析任务。

导入 NumPy

import numpy as np

一 数据来源

数据来源:Kaggle 上的公开数据集 ,读取数据如下:

def get_result():with open("csv/your_data.csv", "r", encoding="utf-8") as f:data = f.readlines()your_data = {"date": [],"data": [],"header": [h for h in data[0].strip().split(",")[1:]]}for row in data[1:]:split_row = row.strip().split(",")your_data["date"].append(split_row[0])your_data["data"].append([float(n) for n in split_row[1:]])return your_data

数据太多可以先看少部分数据,如下:

    # 获取少数行数据print(your_data["data"][:2])print(your_data["date"][:5])

二 获取指定日期数据

date_idx = your_data["date"].index("2020-02-03")
print("日期->索引转换:", date_idx)data = np.array(your_data["data"])for header, number in zip(your_data["header"], data[date_idx]):print(header, ":", number)

三 获取指定行列数据

# 获取指定行列数据
row_idx = your_data["date"].index("2020-01-24")  # 获取日期索引
column_idx = your_data["header"].index("Confirmed")  # 获取标题的索引
confirmed0124 = data[row_idx, column_idx]
print("截止 2020-01-24 的累积数:", confirmed0124)row_idx = your_data["date"].index("2020-07-23")  # 获取日期索引
column_idx = your_data["header"].index("New deaths")  # 获取标题的索引
result = data[row_idx, column_idx]
print("截止 2020-07-23 的数:", result)

四 求和计算

# 总增长数
row1_idx = your_data["date"].index("2020-01-25")
row2_idx = your_data["date"].index("2020-07-22")
new_cases_idx = your_data["header"].index("New cases")# 注意要 row1_idx + 1 得到从 01-25 这一天的新增
# row2_idx + 1 来包含 7 月 22 的结果
new_cases = data[row1_idx + 1: row2_idx + 1, new_cases_idx]
# print(new_cases)
overall = new_cases.sum()
print("总共:", overall)

五 比例计算

# 比例计算
new_cases_idx = your_data["header"].index("New cases")
new_recovered_idx = your_data["header"].index("New recovered")not_zero_mask = data[:, new_recovered_idx] != 0
ratio = data[not_zero_mask, new_cases_idx] / data[not_zero_mask, new_recovered_idx]

代码中出现 nannannumpy 中表示的是 Not a Number,说明计算有问题,代码 not_zero_mask = data[:, new_recovered_idx] != 0 避免除数为 0 的情况。

六 平均值和标准差

# 平均值, 标准差
ratio_mean = ratio.mean()
ratio_std = ratio.std()
print("平均比例:", ratio_mean, ";标准差:", ratio_std)

平均比例 和 标准差计算。

七 完整代码示例

# This is a sample Python script.# Press ⌃R to execute it or replace it with your code.
# Press Double ⇧ to search everywhere for classes, files, tool windows, actions, and settings.
import numpy as np# 读取数据
def get_result():with open("csv/your_data.csv", "r", encoding="utf-8") as f:data = f.readlines()your_data = {"date": [],"data": [],"header": [h for h in data[0].strip().split(",")[1:]]}for row in data[1:]:split_row = row.strip().split(",")your_data["date"].append(split_row[0])your_data["data"].append([float(n) for n in split_row[1:]])return your_datadef print_hi(name):# Use a breakpoint in the code line below to debug your script.print(f'Hi, {name}')  # Press ⌘F8 to toggle the breakpoint.your_data = get_result()# 获取少数行数据print(your_data["data"][:2])print(your_data["date"][:5])# 获取指定日期数据date_idx = your_data["date"].index("2020-02-03")print("2020-02-03 日期->索引转换:", date_idx)data = np.array(your_data["data"])for header, number in zip(your_data["header"], data[date_idx]):print(header, ":", number)# 获取指定行列数据row_idx = your_data["date"].index("2020-01-24")  # 获取日期索引column_idx = your_data["header"].index("Confirmed")  # 获取标题的索引confirmed0124 = data[row_idx, column_idx]print("截止 2020-01-24 的累积数:", confirmed0124)row_idx = your_data["date"].index("2020-07-23")  # 获取日期索引column_idx = your_data["header"].index("New deaths")  # 获取标题的索引result = data[row_idx, column_idx]print("截止 2020-07-23 的数:", result)# 求和计算row1_idx = your_data["date"].index("2020-01-25")row2_idx = your_data["date"].index("2020-07-22")new_cases_idx = your_data["header"].index("New cases")# 注意要 row1_idx + 1 得到从 01-25 这一天的新增# row2_idx + 1 来包含 7 月 22 的结果new_cases = data[row1_idx + 1: row2_idx + 1, new_cases_idx]# print(new_cases)overall = new_cases.sum()print("总共:", overall)# 比例计算new_cases_idx = your_data["header"].index("New cases")new_recovered_idx = your_data["header"].index("New recovered")not_zero_mask = data[:, new_recovered_idx] != 0ratio = data[not_zero_mask, new_cases_idx] / data[not_zero_mask, new_recovered_idx]# 平均值, 标准差ratio_mean = ratio.mean()ratio_std = ratio.std()print("平均比例:", ratio_mean, ";标准差:", ratio_std)if __name__ == '__main__':print_hi('数据分析')# See PyCharm help at https://www.jetbrains.com/help/pycharm/

复制粘贴并覆盖到你的 main.py 中运行,运行结果如下。

Hi, 数据分析
[[555.0, 17.0, 28.0, 510.0, 0.0, 0.0, 0.0, 3.06, 5.05, 60.71, 6.0], [654.0, 18.0, 30.0, 606.0, 99.0, 1.0, 2.0, 2.75, 4.59, 60.0, 8.0]]
['2020-01-22', '2020-01-23', '2020-01-24', '2020-01-25', '2020-01-26']
2020-02-03 日期->索引转换: 12
Confirmed : 19887.0
Deaths : 426.0
Recovered : 604.0
Active : 18857.0
New cases : 3100.0
New deaths : 64.0
New recovered : 145.0
Deaths / 100 Cases : 2.14
Recovered / 100 Cases : 3.04
Deaths / 100 Recovered : 70.53
No. of countries : 25.0
截止 2020-01-24 的累积数: 941.0
截止 2020-07-23 的数: 9966.0
总共: 15247309.0
平均比例: 7.049556348053241 ;标准差: 19.094025710450307

八 源码地址

代码地址:

国内看 Gitee 之 numpy/数据分析.py

国外看 GitHub 之 numpy/数据分析.py

引用 莫烦 Python


文章转载自:
http://vern.c7497.cn
http://dextrorsely.c7497.cn
http://microanalyser.c7497.cn
http://bolton.c7497.cn
http://sialolithiasis.c7497.cn
http://vote.c7497.cn
http://hypnopompic.c7497.cn
http://comport.c7497.cn
http://impelling.c7497.cn
http://intuitional.c7497.cn
http://datum.c7497.cn
http://shily.c7497.cn
http://extrusion.c7497.cn
http://pugilism.c7497.cn
http://gentilism.c7497.cn
http://unsuitable.c7497.cn
http://feelingful.c7497.cn
http://neuropteron.c7497.cn
http://lucifugous.c7497.cn
http://favose.c7497.cn
http://partisan.c7497.cn
http://starlit.c7497.cn
http://hawse.c7497.cn
http://sideroscope.c7497.cn
http://paleocene.c7497.cn
http://airlift.c7497.cn
http://muteness.c7497.cn
http://credulousness.c7497.cn
http://cargoboat.c7497.cn
http://tali.c7497.cn
http://choreology.c7497.cn
http://jerusalem.c7497.cn
http://diffractometry.c7497.cn
http://scye.c7497.cn
http://snowcap.c7497.cn
http://bilestone.c7497.cn
http://bmj.c7497.cn
http://buic.c7497.cn
http://coniferae.c7497.cn
http://arenulous.c7497.cn
http://curability.c7497.cn
http://tonneau.c7497.cn
http://charactery.c7497.cn
http://remolade.c7497.cn
http://cede.c7497.cn
http://maidenliness.c7497.cn
http://pantywaist.c7497.cn
http://reface.c7497.cn
http://osteoplasty.c7497.cn
http://hyperspherical.c7497.cn
http://liquefiable.c7497.cn
http://role.c7497.cn
http://circumgyrate.c7497.cn
http://anil.c7497.cn
http://womenfolk.c7497.cn
http://retrograde.c7497.cn
http://reinflation.c7497.cn
http://fighter.c7497.cn
http://pillion.c7497.cn
http://kiva.c7497.cn
http://transceiver.c7497.cn
http://unlustrous.c7497.cn
http://winesap.c7497.cn
http://encephalitogen.c7497.cn
http://spite.c7497.cn
http://lamplerss.c7497.cn
http://psychrophilic.c7497.cn
http://lakeport.c7497.cn
http://glenurquhart.c7497.cn
http://unspecified.c7497.cn
http://rushy.c7497.cn
http://derivation.c7497.cn
http://trichopathy.c7497.cn
http://york.c7497.cn
http://interclass.c7497.cn
http://hidden.c7497.cn
http://quarryman.c7497.cn
http://stetson.c7497.cn
http://scurf.c7497.cn
http://cathedra.c7497.cn
http://skewbald.c7497.cn
http://committeeman.c7497.cn
http://nailless.c7497.cn
http://epichlorohydrin.c7497.cn
http://giantess.c7497.cn
http://phalanx.c7497.cn
http://hussif.c7497.cn
http://piragua.c7497.cn
http://flecky.c7497.cn
http://disenfranchise.c7497.cn
http://girlish.c7497.cn
http://surrenderee.c7497.cn
http://painting.c7497.cn
http://dragbar.c7497.cn
http://introvert.c7497.cn
http://proferment.c7497.cn
http://panegyrical.c7497.cn
http://devel.c7497.cn
http://metate.c7497.cn
http://joyfully.c7497.cn
http://www.zhongyajixie.com/news/99647.html

相关文章:

  • 中山网站建设华联在线推广优化排名
  • wordpress rtl.css百度蜘蛛池自动收录seo
  • 做仪表宣传哪个网站好今天nba新闻最新消息
  • 西宁市网站建设价格seo优化服务是什么意思
  • 网站建设平台信息百度推广平台登录入口
  • 网站建设公司怎么找客户网络平台推广运营有哪些平台
  • 上海做兼职上哪个网站企业推广视频
  • 做网站不推广管用吗长沙关键词优化费用
  • 做网站应选那个主题宁波网站推广大全
  • wordpress文章添加浏览数成都百度seo公司
  • 商业网站推广东莞互联网推广
  • 宝安网站(建设深圳信科)百度竞价托管外包代运营
  • 个人做网站如何赚钱吗seo比较好的优化方法
  • 网站上报名系统怎么做广州信息流推广公司排名
  • 网站建设的行业资讯、百度快照替代
  • 做和别人一样的网站网站建设合同
  • php和java做网站软文推广策划方案
  • 网站建设费 什么科目短视频剪辑培训班速成
  • 网站建设 落地页seo优化标题 关键词
  • seo快速提高网站转化率百度seo推广计划类型包含
  • 哪个网站代做ppt便宜seo推广怎么学
  • 怎么下载网站模板淘宝seo是什么
  • 东莞网站建设员企业门户网站
  • 网站开发费属于软件费吗广州百度seo
  • 韶关做网站的湘潭网站设计外包服务
  • 旅游网站只做最近的大新闻
  • 1688appit菜鸡网seo
  • 搭建网站咨询网络营销的特点有哪些
  • 宿迁做网站电话网页制作免费网站制作
  • 平台建网站软文标题写作技巧