任務(wù)1:論文數(shù)據(jù)統(tǒng)計(jì)
任務(wù)主題:論文數(shù)量統(tǒng)計(jì),即統(tǒng)計(jì)2019年全年計(jì)算機(jī)各個(gè)方向論文數(shù)量;
任務(wù)內(nèi)容:賽題的理解、使用?Pandas?讀取數(shù)據(jù)并進(jìn)行統(tǒng)計(jì);
任務(wù)成果:學(xué)習(xí)?Pandas?的基礎(chǔ)操作;
可參考的學(xué)習(xí)資料:開(kāi)源組織Datawhale joyful-pandas項(xiàng)目
數(shù)據(jù)集來(lái)源:數(shù)據(jù)集鏈接;
數(shù)據(jù)集的格式如下:
id:arXiv ID,可用于訪問(wèn)論文;
submitter:論文提交者;
authors:論文作者;
title:論文標(biāo)題;
comments:論文頁(yè)數(shù)和圖表等其他信息;
journal-ref:論文發(fā)表的期刊的信息;
doi:數(shù)字對(duì)象標(biāo)識(shí)符,https://www.doi.org;
report-no:報(bào)告編號(hào);
categories:論文在 arXiv 系統(tǒng)的所屬類(lèi)別或標(biāo)簽;
license:文章的許可證;
abstract:論文摘要;
versions:論文版本;
authors_parsed:作者的信息。
1.3 arxiv論文類(lèi)別介紹
我們從arxiv官網(wǎng),查詢(xún)到論文的類(lèi)別名稱(chēng)以及其解釋如下。
鏈接:https://arxiv.org/help/api/user-manual?的 5.3 小節(jié)的 Subject Classifications 的部分,或?https://arxiv.org/category_taxonomy, 具體的153種paper的類(lèi)別部分如下:
'astro-ph': 'Astrophysics',
'astro-ph.CO': 'Cosmology and Nongalactic Astrophysics',
'astro-ph.EP': 'Earth and Planetary Astrophysics',
'astro-ph.GA': 'Astrophysics of Galaxies',
'cs.AI': 'Artificial Intelligence',
'cs.AR': 'Hardware Architecture',
'cs.CC': 'Computational Complexity',
'cs.CE': 'Computational Engineering, Finance, and Science',
'cs.CV': 'Computer Vision and Pattern Recognition',
'cs.CY': 'Computers and Society',
'cs.DB': 'Databases',
'cs.DC': 'Distributed, Parallel, and Cluster Computing',
'cs.DL': 'Digital Libraries',
'cs.NA': 'Numerical Analysis',
'cs.NE': 'Neural and Evolutionary Computing',
'cs.NI': 'Networking and Internet Architecture',
'cs.OH': 'Other Computer Science',
'cs.OS': 'Operating Systems',
1.4.1 導(dǎo)入package并讀取原始數(shù)據(jù)
# 導(dǎo)入所需的packageimportseabornassns#用于畫(huà)圖frombs4importBeautifulSoup#用于爬取arxiv的數(shù)據(jù)importre#用于正則表達(dá)式,匹配字符串的模式importrequests#用于網(wǎng)絡(luò)連接,發(fā)送網(wǎng)絡(luò)請(qǐng)求,使用域名獲取對(duì)應(yīng)信息importjson#讀取數(shù)據(jù),我們的數(shù)據(jù)為json格式的importpandasaspd#數(shù)據(jù)處理,數(shù)據(jù)分析importmatplotlib.pyplotasplt#畫(huà)圖工具
這里使用的package的版本如下(python 3.7.4):
seaborn:0.9.0
BeautifulSoup:4.8.0
requests:2.22.0
json:0.8.5
pandas:0.25.1
matplotlib:3.1.1
# 讀入數(shù)據(jù)data=[]#初始化#使用with語(yǔ)句優(yōu)勢(shì):1.自動(dòng)關(guān)閉文件句柄;2.自動(dòng)顯示(處理)文件讀取數(shù)據(jù)異常withopen("arxiv-metadata-oai-snapshot.json",'r')asf:forlineinf:data.append(json.loads(line))data=pd.DataFrame(data)#將list變?yōu)閐ataframe格式,方便使用pandas進(jìn)行分析data.shape#顯示數(shù)據(jù)大小
Output: (1778381,14)
其中的1778381表示數(shù)據(jù)總量,14表示特征數(shù),對(duì)應(yīng)我們1.2節(jié)說(shuō)明的論文的14種信息。
data.head()#顯示數(shù)據(jù)的前五行
首先我們先來(lái)粗略統(tǒng)計(jì)論文的種類(lèi)信息:
'''count:一列數(shù)據(jù)的元素個(gè)數(shù);unique:一列數(shù)據(jù)中元素的種類(lèi);top:一列數(shù)據(jù)中出現(xiàn)頻率最高的元素;freq:一列數(shù)據(jù)中出現(xiàn)頻率最高的元素的個(gè)數(shù);'''data["categories"].describe()
count1778381unique61371topastro-phfreq86914Name:categories,dtype:object
以上的結(jié)果表明:共有1338381個(gè)數(shù)據(jù),有61371個(gè)子類(lèi)(因?yàn)橛姓撐牡念?lèi)別是多個(gè),例如一篇paper的類(lèi)別是CS.AI & CS.MM和一篇paper的類(lèi)別是CS.AI & CS.OS屬于不同的子類(lèi)別,這里僅僅是粗略統(tǒng)計(jì)),其中最多的種類(lèi)是astro-ph,即Astrophysics(天體物理學(xué)),共出現(xiàn)了86914次。
由于部分論文的類(lèi)別不止一種,所以下面我們判斷在本數(shù)據(jù)集中共出現(xiàn)了多少種獨(dú)立的數(shù)據(jù)集。
# 所有的種類(lèi)(獨(dú)立的)unique_categories=set([iforlin[x.split(' ')forxindata["categories"]]foriinl])len(unique_categories)unique_categories
這里使用了 split 函數(shù)將多類(lèi)別使用 “ ”(空格)分開(kāi),組成list,并使用 for 循環(huán)將獨(dú)立出現(xiàn)的類(lèi)別找出來(lái),并使用 set 類(lèi)別,將重復(fù)項(xiàng)去除得到最終所有的獨(dú)立paper種類(lèi)。
176{'acc-phys','adap-org','alg-geom','ao-sci','astro-ph','astro-ph.CO','astro-ph.EP','astro-ph.GA','astro-ph.HE','astro-ph.IM','astro-ph.SR','atom-ph','bayes-an','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','plasm-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'}
從以上結(jié)果發(fā)現(xiàn),共有176種論文種類(lèi),比我們直接從?https://arxiv.org/help/api/user-manual?的 5.3 小節(jié)的 Subject Classifications 的部分或?https://arxiv.org/category_taxonomy中的到的類(lèi)別少,這說(shuō)明存在一些官網(wǎng)上沒(méi)有的類(lèi)別,這是一個(gè)小細(xì)節(jié)。不過(guò)對(duì)于我們的計(jì)算機(jī)方向的論文沒(méi)有影響,依然是以下的40個(gè)類(lèi)別,我們從原數(shù)據(jù)中提取的和從官網(wǎng)的到的種類(lèi)是可以一一對(duì)應(yīng)的。
'cs.AI':'Artificial Intelligence','cs.AR': 'HardwareArchitecture','cs.CC': 'ComputationalComplexity','cs.CE': 'ComputationalEngineering,Finance,andScience','cs.CG':'Computational Geometry','cs.CL': 'ComputationandLanguage','cs.CR': 'CryptographyandSecurity','cs.CV':'Computer Vision and Pattern Recognition','cs.CY': 'ComputersandSociety','cs.DB': 'Databases','cs.DC':'Distributed, Parallel, and Cluster Computing','cs.DL': 'DigitalLibraries','cs.DM': 'DiscreteMathematics','cs.DS': 'DataStructuresandAlgorithms','cs.ET': 'EmergingTechnologies','cs.FL':'Formal Languages and Automata Theory','cs.GL': 'GeneralLiterature','cs.GR': 'Graphics','cs.GT': 'ComputerScienceandGameTheory','cs.HC': 'Human-ComputerInteraction','cs.IR': 'InformationRetrieval','cs.IT': 'InformationTheory','cs.LG': 'MachineLearning','cs.LO': 'LogicinComputerScience','cs.MA': 'MultiagentSystems','cs.MM':'Multimedia','cs.MS': 'MathematicalSoftware','cs.NA': 'NumericalAnalysis','cs.NE': 'NeuralandEvolutionaryComputing','cs.NI': 'NetworkingandInternetArchitecture','cs.OH':'Other Computer Science','cs.OS': 'OperatingSystems','cs.PF': 'Performance','cs.PL': 'ProgrammingLanguages','cs.RO': 'Robotics','cs.SC': 'SymbolicComputation','cs.SD': 'Sound','cs.SE': 'SoftwareEngineering','cs.SI': 'SocialandInformationNetworks','cs.SY': 'SystemsandControl',
我們的任務(wù)要求對(duì)于2019年以后的paper進(jìn)行分析,所以首先對(duì)于時(shí)間特征進(jìn)行預(yù)處理,從而得到2019年以后的所有種類(lèi)的論文:
data["year"]=pd.to_datetime(data["update_date"]).dt.year#將update_date從例如2019-02-20的str變?yōu)閐atetime格式,并提取處yeardeldata["update_date"]#刪除 update_date特征,其使命已完成data=data[data["year"]>=2019]#找出 year 中2019年以后的數(shù)據(jù),并將其他數(shù)據(jù)刪除# data.groupby(['categories','year']) #以 categories 進(jìn)行排序,如果同一個(gè)categories 相同則使用 year 特征進(jìn)行排序data.reset_index(drop=True,inplace=True)#重新編號(hào)data#查看結(jié)果
這里我們就已經(jīng)得到了所有2019年以后的論文,下面我們挑選出計(jì)算機(jī)領(lǐng)域內(nèi)的所有文章:
#爬取所有的類(lèi)別website_url=requests.get('https://arxiv.org/category_taxonomy').text#獲取網(wǎng)頁(yè)的文本數(shù)據(jù)soup=BeautifulSoup(website_url,'lxml')#爬取數(shù)據(jù),這里使用lxml的解析器,加速root=soup.find('div',{'id':'category_taxonomy_list'})#找出 BeautifulSoup 對(duì)應(yīng)的標(biāo)簽入口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=[]#進(jìn)行fortintags:ift.name=="h2":level_1_name=t.textlevel_2_code=t.textlevel_2_name=t.textelift.name=="h3":raw=t.textlevel_2_code=re.sub(r"(.*)\((.*)\)",r"\2",raw)#正則表達(dá)式:模式字符串:(.*)\((.*)\);被替換字符串"\2";被處理字符串:rawlevel_2_name=re.sub(r"(.*)\((.*)\)",r"\1",raw)elift.name=="h4":raw=t.textlevel_3_code=re.sub(r"(.*) \((.*)\)",r"\1",raw)level_3_name=re.sub(r"(.*) \((.*)\)",r"\2",raw)elift.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)#根據(jù)以上信息生成dataframe格式的數(shù)據(jù)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" 進(jìn)行分組,在組內(nèi)使用 "archive_name" 進(jìn)行排序df_taxonomy.groupby(["group_name","archive_name"])df_taxonomy
由于這幾天個(gè)人時(shí)間不足,以及確實(shí)是純小白,搭建環(huán)境之后并沒(méi)有完成代碼的實(shí)現(xiàn),接下來(lái)計(jì)劃繼續(xù)學(xué)習(xí)理解。