这是在学习数据分析的一个实例,论文数据分析,这是第一部分,笔者刚学习此项内容,有问题大家提出来,不喜勿喷。

任务1:论文数据统计1

1.1 任务说明

任务主题:论文数量统计,即统计2019年全年计算机各个方向论文数量;
任务内容:赛题的理解、使用 Pandas 读取数据并进行统计;
任务成果:学习 Pandas 的基础操作;
可参考的学习资料:开源组织Datawhale joyful-pandas项目

import pandas as pd
import numpy as np
import json
import re
data  = [] #初始化
#使用with语句优势:1.自动关闭文件句柄;2.自动显示(处理)文件读取数据异常
with open(r'arxiv-metadata-oai-2019.json','r') as f: for line in f: data.append(json.loads(line))data = pd.DataFrame(data) #将list变为dataframe格式,方便使用pandas进行分析
data.shape #显示数据大小
(170618, 14)
data.head(3)
id submitter authors title comments journal-ref doi report-no categories license abstract versions update_date authors_parsed
0 0704.0297 Sung-Chul Yoon Sung-Chul Yoon, Philipp Podsiadlowski and Step... Remnant evolution after a carbon-oxygen white ... 15 pages, 15 figures, 3 tables, submitted to M... None 10.1111/j.1365-2966.2007.12161.x None astro-ph None We systematically explore the evolution of t... [{'version': 'v1', 'created': 'Tue, 3 Apr 2007... 2019-08-19 [[Yoon, Sung-Chul, ], [Podsiadlowski, Philipp,...
1 0704.0342 Patrice Ntumba Pungu B. Dugmore and PP. Ntumba Cofibrations in the Category of Frolicher Spac... 27 pages None None None math.AT None Cofibrations are defined in the category of ... [{'version': 'v1', 'created': 'Tue, 3 Apr 2007... 2019-08-19 [[Dugmore, B., ], [Ntumba, PP., ]]
2 0704.0360 Zaqarashvili T.V. Zaqarashvili and K Murawski Torsional oscillations of longitudinally inhom... 6 pages, 3 figures, accepted in A&A None 10.1051/0004-6361:20077246 None astro-ph None We explore the effect of an inhomogeneous ma... [{'version': 'v1', 'created': 'Tue, 3 Apr 2007... 2019-08-19 [[Zaqarashvili, T. V., ], [Murawski, K, ]]

数据集的格式如下:

id:arXiv ID,可用于访问论文;
submitter:论文提交者;
authors:论文作者;
title:论文标题;
comments:论文页数和图表等其他信息;
journal-ref:论文发表的期刊的信息;
doi:数字对象标识符,https://www.doi.org;
report-no:报告编号;
categories:论文在 arXiv 系统的所属类别或标签;
license:文章的许可证;
abstract:论文摘要;
versions:论文版本;
authors_parsed:作者的信息。

由上可看出该数据有170618条数据,14个特征。

数据预处理

#首先我们先来粗略统计论文的种类信息:
data["categories"].describe()
#count:一列数据的元素个数;
#unique:一列数据中元素的种类;
#top:一列数据中出现频率最高的元素;
#freq:一列数据中出现频率最高的元素的个数;
count     170618
unique     15592
top        cs.CV
freq        5559
Name: categories, dtype: object

以上的结果表明:共有170681个数据,有15592个子类(因为有论文的类别是多个,例如一篇paper的类别是CS.AI & CS.MM和一篇paper的类别是CS.AI & CS.OS属于不同的子类别,这里仅仅是粗略统计),其中最多的种类是CS.CV,即Computer Vision and Pattern Recognition计算机视觉,共出现了5559次。

由于部分论文的类别不止一种,所以下面我们判断在本数据集中共出现了多少种独立的数据集。

unique_categories = set([i for l in [x.split(' ') for x in data["categories"]] for i in l])
len(unique_categories)
#unique_categories#所有的种类(独立的)
172

这里使用了 split 函数将多类别使用 “ ”(空格)分开,组成list,并使用 for 循环将独立出现的类别找出来,并使用 set 类别,将重复项去除得到最终所有的独立paper种类。

unique_categories
{'acc-phys','adap-org','alg-geom','astro-ph','astro-ph.CO','astro-ph.EP','astro-ph.GA','astro-ph.HE','astro-ph.IM','astro-ph.SR','chao-dyn','chem-ph','cmp-lg','comp-gas','cond-mat','cond-mat.dis-nn','cond-mat.mes-hall','cond-mat.mtrl-sci','cond-mat.other','cond-mat.quant-gas','cond-mat.soft','cond-mat.stat-mech','cond-mat.str-el','cond-mat.supr-con','cs.AI','cs.AR','cs.CC','cs.CE','cs.CG','cs.CL','cs.CR','cs.CV','cs.CY','cs.DB','cs.DC','cs.DL','cs.DM','cs.DS','cs.ET','cs.FL','cs.GL','cs.GR','cs.GT','cs.HC','cs.IR','cs.IT','cs.LG','cs.LO','cs.MA','cs.MM','cs.MS','cs.NA','cs.NE','cs.NI','cs.OH','cs.OS','cs.PF','cs.PL','cs.RO','cs.SC','cs.SD','cs.SE','cs.SI','cs.SY','dg-ga','econ.EM','econ.GN','econ.TH','eess.AS','eess.IV','eess.SP','eess.SY','funct-an','gr-qc','hep-ex','hep-lat','hep-ph','hep-th','math-ph','math.AC','math.AG','math.AP','math.AT','math.CA','math.CO','math.CT','math.CV','math.DG','math.DS','math.FA','math.GM','math.GN','math.GR','math.GT','math.HO','math.IT','math.KT','math.LO','math.MG','math.MP','math.NA','math.NT','math.OA','math.OC','math.PR','math.QA','math.RA','math.RT','math.SG','math.SP','math.ST','mtrl-th','nlin.AO','nlin.CD','nlin.CG','nlin.PS','nlin.SI','nucl-ex','nucl-th','patt-sol','physics.acc-ph','physics.ao-ph','physics.app-ph','physics.atm-clus','physics.atom-ph','physics.bio-ph','physics.chem-ph','physics.class-ph','physics.comp-ph','physics.data-an','physics.ed-ph','physics.flu-dyn','physics.gen-ph','physics.geo-ph','physics.hist-ph','physics.ins-det','physics.med-ph','physics.optics','physics.plasm-ph','physics.pop-ph','physics.soc-ph','physics.space-ph','q-alg','q-bio','q-bio.BM','q-bio.CB','q-bio.GN','q-bio.MN','q-bio.NC','q-bio.OT','q-bio.PE','q-bio.QM','q-bio.SC','q-bio.TO','q-fin.CP','q-fin.EC','q-fin.GN','q-fin.MF','q-fin.PM','q-fin.PR','q-fin.RM','q-fin.ST','q-fin.TR','quant-ph','solv-int','stat.AP','stat.CO','stat.ME','stat.ML','stat.OT','stat.TH','supr-con'}
data["year"] = pd.to_datetime(data["update_date"]).dt.year #将update_date从例如2019-02-20的str变为datetime格式,并提取出year
del data["update_date"] #删除 update_date特征,其使命已完成
data = data[data["year"] >= 2019] #找出 year 中2019年的数据,删除其他数据
data.reset_index(drop=True, inplace=True) #编号
data.head()
#爬取所有的类别
import requests
from bs4 import BeautifulSoup
website_url = requests.get('https://arxiv.org/category_taxonomy').text #获取网页的文本数据
soup = BeautifulSoup(website_url,'lxml') #爬取数据,这里使用lxml的解析器,加速
root = soup.find('div',{'id':'category_taxonomy_list'}) #找出 BeautifulSoup 对应的标签入口
tags = root.find_all(["h2","h3","h4","p"], recursive=True) #读取 tags#初始化 str 和 list 变量
level_1_name = ""
level_2_name = ""
level_2_code = ""
level_1_names = []
level_2_codes = []
level_2_names = []
level_3_codes = []
level_3_names = []
level_3_notes = []#进行
for t in tags:if t.name == "h2":level_1_name = t.text    level_2_code = t.textlevel_2_name = t.textelif t.name == "h3":raw = t.textlevel_2_code = re.sub(r"(.*) \((.*)\)",r"\2",raw) #正则表达式:模式字符串:(.*)\((.*)\);被替换字符串"\2";被处理字符串:rawlevel_2_name = re.sub(r"(.*) \((.*)\)",r"\1",raw)elif t.name == "h4":raw = t.textlevel_3_code = re.sub(r"(.*) \((.*)\)",r"\1",raw)level_3_name = re.sub(r"(.*) \((.*)\)",r"\2",raw)elif t.name == "p":notes = t.textlevel_1_names.append(level_1_name)level_2_names.append(level_2_name)level_2_codes.append(level_2_code)level_3_names.append(level_3_name)level_3_codes.append(level_3_code)level_3_notes.append(notes)#根据以上信息生成dataframe格式的数据
df_taxonomy = pd.DataFrame({'group_name' : level_1_names,'archive_name' : level_2_names,'archive_id' : level_2_codes,'category_name' : level_3_names,'categories' : level_3_codes,'category_description': level_3_notes})#按照 "group_name" 进行分组,在组内使用 "archive_name" 进行排序
df_taxonomy.groupby(["group_name","archive_name"])
df_taxonomy.head()
group_name archive_name archive_id category_name categories category_description
0 Computer Science Computer Science Computer Science Artificial Intelligence cs.AI Covers all areas of AI except Vision, Robotics...
1 Computer Science Computer Science Computer Science Hardware Architecture cs.AR Covers systems organization and hardware archi...
2 Computer Science Computer Science Computer Science Computational Complexity cs.CC Covers models of computation, complexity class...
3 Computer Science Computer Science Computer Science Computational Engineering, Finance, and Science cs.CE Covers applications of computer science to the...
4 Computer Science Computer Science Computer Science Computational Geometry cs.CG Roughly includes material in ACM Subject Class...

上面代码中的正则操作,这里我们使用re.sub来用于替换字符串中的匹配项
‘’’
pattern : 正则中的模式字符串。
repl : 替换的字符串,也可为一个函数。
string : 要被查找替换的原始字符串。
count : 模式匹配后替换的最大次数,默认 0 表示替换所有的匹配。
flags : 编译时用的匹配模式,数字形式。
其中pattern、repl、string为必选参数
‘’’

re.sub(pattern, repl, string, count=0, flags=0)

#例如
import rephone = "2004-959-559 # 这是一个电话号码"# 删除注释
num = re.sub(r'#.*$', "", phone)
print ("电话号码 : ", num)# 移除非数字的内容
num = re.sub(r'\D', "", phone)
print ("电话号码 : ", num)
电话号码 :  2004-959-559
电话号码 :  2004959559

re.sub(r"(.)((.))",r"\2",raw)
对应的参数

正则中的模式字符串 pattern 的格式为 “任意字符” + “(” + “任意字符” + “)”。
替换的字符串 repl 为第2个分组的内容。
要被查找替换的原始字符串 string 为原始的爬取的数据。

数据分析及可视化

首先看一下所有大类的paper数量分布:

df = data.merge(df_taxonomy, on="categories", how="left").drop_duplicates(["id","group_name"]).groupby("group_name").agg({"id":"count"}).sort_values(by="id",ascending=False).reset_index()
df
group_name id
0 Physics 38379
1 Mathematics 24495
2 Computer Science 18087
3 Statistics 1802
4 Electrical Engineering and Systems Science 1371
5 Quantitative Biology 886
6 Quantitative Finance 352
7 Economics 173
import matplotlib.pyplot as plt
fig = plt.figure(figsize=(15,12))
explode = (0, 0, 0, 0.2, 0.3, 0.3, 0.2, 0.1)
plt.pie(df["id"],  labels=df["group_name"], autopct='%1.2f%%', startangle=160, explode=explode)
plt.tight_layout()
plt.show()


统计在计算机各个子领域2019年的paper数量:

group_name="Computer Science"
cats = data.merge(df_taxonomy, on="categories").query("group_name == @group_name")
cats.groupby(["year","category_name"]).count().reset_index().pivot(index="category_name", columns="year",values="id")
year 2019
category_name
Artificial Intelligence 558
Computation and Language 2153
Computational Complexity 131
Computational Engineering, Finance, and Science 108
Computational Geometry 199
Computer Science and Game Theory 281
Computer Vision and Pattern Recognition 5559
Computers and Society 346
Cryptography and Security 1067
Data Structures and Algorithms 711
Databases 282
Digital Libraries 125
Discrete Mathematics 84
Distributed, Parallel, and Cluster Computing 715
Emerging Technologies 101
Formal Languages and Automata Theory 152
General Literature 5
Graphics 116
Hardware Architecture 95
Human-Computer Interaction 420
Information Retrieval 245
Logic in Computer Science 470
Machine Learning 177
Mathematical Software 27
Multiagent Systems 85
Multimedia 76
Networking and Internet Architecture 864
Neural and Evolutionary Computing 235
Numerical Analysis 40
Operating Systems 36
Other Computer Science 67
Performance 45
Programming Languages 268
Robotics 917
Social and Information Networks 202
Software Engineering 659
Sound 7
Symbolic Computation 44
Systems and Control 415

使用 merge 函数,对于两个dataframe 共同的特征 categories 进行合并并且进行查询。然后我们再对于数据进行统计和排序

我们可以从结果看出,Computer Vision and Pattern Recognition(计算机视觉与模式识别)类是CS中paper数量最多的子类,遥遥领先于其他的CS子类,并且paper的数量还在逐年增加;另外,Computation and Language(计算与语言)、Cryptography and Security(密码学与安全)以及 Robotics(机器人学)的2019年paper数量均超过1000或接近1000,这与我们的认知是一致的。


论文数据分析-1(论文数据统计)相关推荐

  1. 论文数据分析-4(论文种类分类)

    任务4:论文种类分类 这部分内容作者还没有完成,先放出来大家参考,作者会继续补充,不喜勿喷 4.1 任务说明 学习主题:论文分类(数据建模任务),利用已有数据建模,对新论文进行类别分类: 学习内容:使 ...

  2. 数据分析之学术前沿分析 任务1:论文数据统计

    任务1:论文数据统计 1.1 任务说明 1.2 数据集介绍 1.3 arxiv论⽂文类别介绍 1.4 具体代码实现以及讲解 1.4.1 导⼊入package并读取原始数据 1.4.2 数据预处理理 1 ...

  3. 数据分析---arXiv论文数据统计

    这里写目录标题 1.论文数据统计 1.1 任务说明 1.2 数据集介绍 1.3 arxiv论文类别介绍 1.4 具体代码实现以及讲解 1.4.1 导入package并读取原始数据 1.4.2 数据预处 ...

  4. 数据分析---论文数据统计

    数据分析-论文数据统计 目录 1.1任务说明 1.2数据集介绍 1.3arxiv论文类别介绍 1.4具体代码实现 1.4.1导入package并读取原始数据 1.4.2数据预处理 1.4.3数据分析及 ...

  5. 【数据分析 01】论文数据统计 --学术前沿分析

    数据来源:https://www.kaggle.com/Cornell-University/arxiv 目的:统计2019年全年,计算机各个方向论文数量 以下基于jupyter环境实现 1.导入数据 ...

  6. 【竞赛算法学习】学术前沿趋势分析-论文数据统计

    任务1:论文数据统计 1.1 任务说明 任务主题:论文数量统计,即统计2019年全年计算机各个方向论文数量: 任务内容:赛题的理解.使用 Pandas 读取数据并进行统计: 任务成果:学习 Panda ...

  7. 论文数据统计Task1

    论文数据统计Task1 数据集 具体代码实现 导入所需包 读入数据并查看数据大小 显示数据的前五行 进行数据预处理 查看所有论文的种类 特征处理 筛选数据 数据分析及可视化 心得体会 数据集 链接:数 ...

  8. 【学术前沿分析】1 论文数据统计

    论文数据统计 1.1 任务说明 读取json数据.爬取数据: 论文数量统计,即统计2019年全年计算机各个方向论文数量: 1.2 数据集介绍 数据集来源:数据集链接: 数据集的格式如下: id:arX ...

  9. 学习分享:学术前言趋势分析1—论文数据统计

    文章目录 1.数据集介绍 2.代码学习心得 (1) split()函数 (2) 正则表达式 (3) 数据分析及可视化 3.具体代码实现 学习主题:论文数量统计,统计2019年全年,计算机各个方向论文数 ...

最新文章

  1. 【C++】何时需要自定义拷贝构造函数和赋值符
  2. [Swust OJ 404]--最小代价树(动态规划)
  3. 【Android 异步操作】Handler ( 主线程中的 Handler 与 Looper | Handler 原理简介 )
  4. 字节序及字节排序函数
  5. scrapy框架_Python:Scrapy框架
  6. oracle 重复的记录数,如何确定Oracle数据库表中重复的记录
  7. Cesium 加载天地图
  8. bat 自动输入密码_「docker实战篇」python的docker爬虫技术移动自动化uiautomator工具(16)...
  9. [转载] java调用c++的dll及java.lang.UnsatisfiedLinkError解决方法
  10. js语法、关键保留字、变量、数据类型
  11. MySQL Table is marked as crashed and should be repaired
  12. 865程序设计c语言,2018年江西师范大学865程序设计(C语言)考研大纲
  13. 网页设计引入的字体包过大的压缩方法
  14. IDEA 热部署插件 JRebel 激活
  15. 【密码学 | CTF】培根密码
  16. 使php爬虫能够长期运行的一点总结
  17. 神经网络分类效果评价——多元分类交叉熵
  18. 一种测试方法论RST(非广告)
  19. 计算机网络—IP地址及其表示方法
  20. ILOG Gantt 3.0 注册机

热门文章

  1. cursor:pointer属性,鼠标经过或点击有小手样式
  2. 电路+模电+电力电子基础
  3. 6.12 C语言练习([C语言训练]求函数值:按如下递归公式求函数值。 )
  4. Html+css+js实战:百度搜索框样式实现
  5. java utf-8 转 gbk / gbk 转 utf-8
  6. 芯片噪声测试软件,教你如何测量芯片数字模拟噪声 - 全文
  7. 各省份非金融类对外直接投资存量(2003-2020年)
  8. 网吧服务器是起什么作用的,网吧服务器缓存命中率是什么,有什么用?
  9. Charles抓包 - 手机
  10. 2022/06/03密码