任务2:论文作者统计
2.1 任务统计
- 任务主题:论文作者统计,统计所有论文作者出现频率Top10的姓名;
- 任务内容:论文作者的统计、使用 Pandas 读取数据并使用字符串操作;
- 任务成果:学习 Pandas 的字符串操作;
2.2 具体代码实现与讲解
import pandas as pd
import matplotlib.pyplot as plt
import json
data = []
with open('arxiv-metadata-oai-snapshot.json','r') as f:
for idx,line in enumerate(f):
d = json.loads(line)
d = {'authors':d['authors'],'categories':d['categories'],'authors_parsed':d['authors_parsed']}
data.append(d)
data = pd.DataFrame(data)
2.3 数据统计
接下来我们将完成以下统计操作:
- 统计所有作者姓名出现频率的Top10;
- 统计所有作者姓(姓名最后一个单词)的出现频率的Top10;
- 统计所有作者姓第一个字符的评率;
为了节约计算时间,下面选择部分类别下的论文进行处理:
# 选择类别为 cs.CV下面的论文
data2 = data[data['categories'].apply(lambda x: 'cs.CV' in x)]
# 拼接所有作者
all_authors = sum(data2['authors_parsed'],[])
以上操作把all_authors变成了一个list,其中每个元素为一个作者的姓名
# 拼接所有的作者
authors_names = [' '.join(x) for x in all_authors]
authors_names = pd.DataFrame(authors_names)
authors_names

image.png
2.3.1 统计作者频率
# 绘制前10的作者直方图
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')

image.png
2.3.2 统计论文作者的姓氏
authors_lastnames = [x[0] for x in all_authors]
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')

image.png
从统计结果来看,以上作者的姓氏全部为华人
2.3.3 统计所有作者第一个姓名的第一个字符的频率
authors_names = [x[0] for x in all_authors]
authors_firstOne = [x[0] for x in authors_names]
authors_firstOne = pd.DataFrame(authors_firstOne)
authors_firstOne

image.png
plt.figure(figsize=(10,6))
authors_firstOne[0].value_counts().head(15).plot(kind='bar')
names = authors_firstOne[0].value_counts().index.values[:15]
_ = plt.xticks(range(0,len(names)),names)
plt.ylabel('Count')
plt.xlabel('First_alphabet')

image.png