阿里云天池学习赛-零基础入门数据分析-学术前沿趋势分析(task2)

该博客介绍了如何从零开始进行数据分析,以学术前沿趋势分析为例,具体阐述了如何处理数据集,提取论文作者信息。首先,通过读取arXiv数据集并筛选cs.CV类别的论文,然后对作者信息进行处理,统计出现频率最高的前10位作者。通过代码解析展示了数据读取、筛选、作者名字提取和统计的步骤,最后用图表展示作者出现频率分布。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


前言

本博客主要记录零基础入门数据分析-学术前沿趋势分析的自己的一些理解,主要是解题思路以及代码的解释。大赛地址:零基础入门数据分析-学术前沿趋势分析


一、赛题描述及数据说明

1:数据集的格式如下:

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

2:数据集格式举例:

“root”:{
“id”:string"0704.0001"
“submitter”:string"Pavel Nadolsky"
“authors”:string"C. Bal’azs, E. L. Berger, P. M. Nadolsky, C.-P. Yuan"
“title”:string"Calculation of prompt diphoton production cross sections at Tevatron and LHC energies"
“comments”:string"37 pages, 15 figures; published version"
“journal-ref”:string"Phys.Rev.D76:013009,2007"
“doi”:string"10.1103/PhysRevD.76.013009"
“report-no”:string"ANL-HEP-PR-07-12"
“categories”:string"hep-ph"
“license”:NULL
“abstract”:string" A fully differential calculation in perturbative quantum chromodynamics is presented for the production of massive photon pairs at hadron colliders. All next-to-leading order perturbative contributions from quark-antiquark, gluon-(anti)quark, and gluon-gluon subprocesses are included, as well as all-orders resummation of initial-state gluon radiation valid at next-to-next-to leading logarithmic accuracy. The region of phase space is specified in which the calculation is most reliable. Good agreement is demonstrated with data from the Fermilab Tevatron, and predictions are made for more detailed tests with CDF and DO data. Predictions are shown for distributions of diphoton pairs produced at the energy of the Large Hadron Collider (LHC). Distributions of the diphoton pairs from the decay of a Higgs boson are contrasted with those produced from QCD processes at the LHC, showing that enhanced sensitivity to the signal can be obtained with judicious selection of events."
“versions”:[
0:{
“version”:string"v1"
“created”:string"Mon, 2 Apr 2007 19:18:42 GMT"
}
1:{
“version”:string"v2"
“created”:string"Tue, 24 Jul 2007 20:10:27 GMT"
}]
“update_date”:string"2008-11-26"
“authors_parsed”:[
0:[
0:string"Balázs"
1:string"C."
2:string""]
1:[
0:string"Berger"
1:string"E. L."
2:string""]
2:[
0:string"Nadolsky"
1:string"P. M."
2:string""]
3:[
0:string"Yuan"
1:string"C. -P."
2:string""]]
}

二、task2论文作者统计(数据统计任务):统计所有论文作者出现评率Top10的姓名;

1.题目意思解读及整体思路分析

在读取数据集后,这样就得到了所有论文,接着就可以提取每篇论文的作者名字,提取出来转成DataFrame的格式,直接就可以统计前10的信息。

2.各节代码展示与讲解

2.1:先读取数据集:

def readArxivFile(path, columns = ['id','submitter','authors','title','comments','journal-ref','doi','report-no','categories', 'license', 'abstract', 'versions',
       'update_date', 'authors_parsed'] , count = None):
    # 读取文件的函数,path:文件路径,columns:需要选择的列,count:读取行数
    data = []
    with open(path,'r') as f:
        for idx, line in enumerate(f):
            if idx == count:
                break
            d = json.loads(line)#把每条数据(json格式) --> 转换成python对象,这里是转换成字典类型
            d = {col: d[col] for col in columns}#更改d,只用获取原数据集中的一部分,即columns的部分
            data.append(d)

    data = pd.DataFrame(data)#将字典类型转换成DataFrame类型
    return data


	#读取100000条数据
	data = readArxivFile('arxiv-metadata-oai-2019.json',['id', 'authors', 'categories', 'authors_parsed'],
                    100000)

2.1.1: json.load(): 把json格式数据 -> python对象(这里转换成了字典类型),看下图,上面是json格式数据,下面是python的字典类型。

在这里插入图片描述

2.1.2: d = {col: d[col] for col in columns} 这里字典类型的索引是col,也就是columns中的每一个,其对应的键值是d[col],从而构成新年的内容,即只选取原数据中的一部分键值对。

2.2:这里为了节约计算的时间,只从数据集中选取论文类别为cs.CV的论文

  #选择类别为cs.CV的论文
    data2 = data[data['categories'].apply(lambda x: 'cs.CV' in x)]
    # in: 属于里面就是True 不属于里面就是False,data['categories']的每一行就是x,lambda表达式返回的是True,或者False,
    # apply()就是直接返回lambda的值data[true] 即这一行留下来,data[False]即这一行删除

2.2.1 这里注意lambda表达式的应用,lambda a,b : a+b -> a和b相当于函数的参数,a+b是函数的表达式(用于返回函数结果)。

2.2.2 pandas 的 apply() 函数可以作用于 Series 或者整个 DataFrame,这里起着改变data[‘categories’]的作用,留下或者删除

2.3:获取论文的作者,思路是通过对’authors_parsed’字段的处理,从而来获取作者的名字(说明下每篇论文的作者可能只有一位,也可能不止一位,)
2.3.1: 先从data里把每篇的作者取出来,并拼接成一个list[]

    all_authors = sum(data2['authors_parsed'],[])     
    #[["Mokhov","Serguei A.","","for the MARF R&D Group"],["Sinclair","Stephen","","for the MARF R&D Group"],["Cl\u00e9ment","Ian","","for the MARF R&D Group"],["Nicolacopoulos","Dimitrios","","for the MARF R&D Group"]]}
    #这篇有四个作者,
    # ['Mokhov', 'Serguei A.', '', 'for the MARF R&D Group'],
    # ['Sinclair', 'Stephen', '', 'for the MARF R&D Group'],
    # ['Clément', 'Ian', '', 'for the MARF R&D Group'],
    # ['Nicolacopoulos', 'Dimitrios', '', 'for the MARF R&D Group'],
    # sum()负责把一个个的list拼接成一个大的list,

原来数据格式如图所示:
在这里插入图片描述

将其变成一个大的list后如图所示:
在这里插入图片描述

2.3.2: 再把每篇文章作者的名字格式进行处理,把名字拼接成以空格隔开的形式,再并转换成DataFrame的形式。

	authors_names = [' '.join(x) for x in all_authors]#join():返回通过指定字符连接序列中元素后生成的新字符串。
    #即以空格将每一个list内的名字连接起来,['Pal', 'Mahesh', '']-> “Pal Mahesh”
    authors_names = pd.DataFrame(authors_names)

把名字拼接成以空格隔开的格式如图:
在这里插入图片描述

变成DataFrame的格式如图:
在这里插入图片描述

2.3.3: 提取姓名的前十名并作可视化展示

 #根据作者频率绘制直方图
    plt.figure(figsize=(10,6))
    authors_names[0].value_counts().head(10).plot(kind='barh')

    #修改图配置
    names = authors_names[0].value_counts().index.values[:10]
    _ = plt.yticks(range(0,len(names)),names)
    plt.ylabel('Author')
    plt.xlabel('Count')

2.4:统计下作者的姓(利用“authors_parsed”字段中作者第一个单词)

    #统计作者的姓,也就是authors_parsed字段中的第一个单词
    authors_lastnames = [x[0] for x in all_authors]#所有姓,加入到list中
    authors_lastnames = pd.DataFrame(authors_lastnames)

    plt.figure(figsize=(10,6))
    authors_lastnames[0].value_counts().head(10).plot(kind='barh')
    names = authors_lastnames[0].value_counts().index.values[:10]
    _ = plt.yticks(range(0, len(names)), names)
    plt.ylabel('Author')
    plt.xlabel('Count')
    plt.show()

3.完整代码展示

import seaborn as sns
from bs4 import BeautifulSoup
import re
import requests
import json
import pandas as pd
import matplotlib.pyplot as plt

def readArxivFile(path, columns=['id', 'submitter', 'authors', 'title', 'comments', 'journal-ref', 'doi',
       'report-no', 'categories', 'license', 'abstract', 'versions',
       'update_date', 'authors_parsed'],count=None):
    data = []
    with open(path, 'r') as f:
        for idx ,line in enumerate(f):
            if idx == count:
                break
            d = json.loads(line)
            d = {col : d[col] for col in columns}
            data.append(d)

    data = pd.DataFrame(data)
    return data


if __name__ == "__main__":
    data = readArxivFile('arxiv-metadata-oai-2019.json',['id', 'authors', 'categories', 'authors_parsed'],
                    100000)
    #选择类别为cs.CV的论文
    data2 = data[data['categories'].apply(lambda x: 'cs.CV' in x)]
    # in: 属于里面就是True 不属于里面就是False,data['categories']的每一行就是x,lambda表达式返回的是True
    # 或者False,apply()就是直接返回lambda的值data[true] 即这一行留下来,data[False]即这一行删除

    all_authors = sum(data2['authors_parsed'],[]) 
    #[["Mokhov","Serguei A.","","for the MARF R&D Group"],["Sinclair","Stephen","","for the MARF R&D Group"],["Cl\u00e9ment","Ian","","for the MARF R&D Group"],["Nicolacopoulos","Dimitrios","","for the MARF R&D Group"]]}
    #这篇有四个作者,
    # ['Mokhov', 'Serguei A.', '', 'for the MARF R&D Group'],
    # ['Sinclair', 'Stephen', '', 'for the MARF R&D Group'],
    # ['Clément', 'Ian', '', 'for the MARF R&D Group'],
    # ['Nicolacopoulos', 'Dimitrios', '', 'for the MARF R&D Group'],
    # sum()负责把一个个的list拼接成一个大的list,

    authors_names = [' '.join(x) for x in all_authors]#join():返回通过指定字符连接序列中元素后生成的新字符串。
    #即以空格将每一个list内的名字连接起来,['Pal', 'Mahesh', '']-> “Pal Mahesh”

    authors_names = pd.DataFrame(authors_names)

    #根据作者频率绘制直方图
    plt.figure(figsize=(10,6))
    authors_names[0].value_counts().head(10).plot(kind='barh')

    #修改图配置
    names = authors_names[0].value_counts().index.values[:10]
    _ = plt.yticks(range(0,len(names)),names)
    plt.ylabel('Author')
    plt.xlabel('Count')
    #plt.show()

    #统计作者的姓,也就是authors_parsed字段中的第一个单词
    authors_lastnames = [x[0] for x in all_authors]#所有姓,加入到list中
    authors_lastnames = pd.DataFrame(authors_lastnames)

    plt.figure(figsize=(10,6))
    authors_lastnames[0].value_counts().head(10).plot(kind='barh')
    names = authors_lastnames[0].value_counts().index.values[:10]
    _ = plt.yticks(range(0, len(names)), names)
    plt.ylabel('Author')
    plt.xlabel('Count')
    plt.show()

4.代码中几个需要注意的地方:

1)lambda表达式的理解:可以理解成一个带有参数,并且有返回值的函数;
apply()函数:主要用于对series,和DataFrame的操作;
sum()函数:sum(iterable[, start]),iterable – 可迭代对象,如:列表、元组、集合。start – 指定相加的参数,如果没有设置这个值,默认为0,最后都加到start里面。
join()函数:str.join(sequence),sequence – 要连接的元素序列,以指定字符串(str)去连接sequence。

	data2 = data[data['categories'].apply(lambda x: 'cs.CV' in x)]
    # in: 属于里面就是True 不属于里面就是False,data['categories']的每一行就是x,lambda表达式返回的是True
    # 或者False,apply()就是直接返回lambda的值data[true] 即这一行留下来,data[False]即这一行删除
    all_authors = sum(data2['authors_parsed'],[]) #拼接所有作者,说明下:每篇文章其实只有一个作者,只是名字很长
    authors_names = [' '.join(x) for x in all_authors]#join():返回通过指定字符连接序列中元素后生成的新字符串。
心跳信号分类预测是一个基于数据挖掘的重要任务,本次回答将介绍在天池-零基础入门数据挖掘比中心跳信号分类预测项目中的EDA(探索性数据分析分析过程和相应代码。 首先,我们需要导入所需的库和数据集,如下所示: ```python import pandas as pd import numpy as np # 导入训练集 train_df = pd.read_csv('train.csv') # 导入测试集 test_df = pd.read_csv('test.csv') ``` 接下来,我们可以进行一些基本的数据探索,如查看数据集的形状和前几行数据等: ```python # 查看训练集形状 train_df.shape # 查看训练集前几行数据 train_df.head() ``` 然后,我们可以对数据集进行一些统计性分析,如计算各个特征的缺失值数量、平均值、标准差等: ```python # 计算训练集特征的缺失值数量 train_df.isnull().sum() # 计算训练集特征的均值 train_df.mean() # 计算训练集特征的标准差 train_df.std() ``` 接下来,我们可以对数据集中的特征进行可视化分析,以便更好地理解数据: ```python import matplotlib.pyplot as plt # 绘制训练集中特征的直方图 train_df.hist(figsize=(10, 10), bins=50) plt.show() # 绘制训练集中特征之间的相关性热图 correlation = train_df.corr() plt.figure(figsize=(10, 10)) plt.imshow(correlation, cmap='hot', interpolation='nearest') plt.colorbar() plt.xticks(np.arange(len(correlation.columns)), correlation.columns, rotation=90) plt.yticks(np.arange(len(correlation.columns)), correlation.columns) plt.show() ``` 最后,我们可以对数据集中的特征进行预处理和特征工程,以提高模型的性能: ```python from sklearn.preprocessing import StandardScaler # 对训练集的特征进行标准化 scaler = StandardScaler() scaled_features = scaler.fit_transform(train_df.drop('target', axis=1)) # 构建新的训练集 new_train_df = pd.DataFrame(scaled_features, columns=train_df.columns[:-1]) new_train_df['target'] = train_df['target'] ``` 以上就是在天池-零基础入门数据挖掘比中心跳信号分类预测项目中的EDA分析过程和相应代码。通过探索性数据分析,我们可以更好地理解数据集,并为后续的特征工程和模型训练做好准备。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值