data =[]#初始化#使用with语句优势:1.自动关闭文件句柄;2.自动显示(处理)文件读取数据异常withopen("/home/aistudio/data/data67990/arxiv-metadata-oai-2019.json",'r')as f:for idx, line inenumerate(f):
d = json.loads(line)
d ={
'authors_parsed': d['authors_parsed']}
data.append(d)
data = pd.DataFrame(data)#将list变为dataframe格式,方便使用pandas进行分析
import networkx as nx
# 创建无向图
G = nx.Graph()# 只用五篇论文进行构建for row in data.iloc[:5].itertuples():
authors = row[1]
authors =[' '.join(x[:-1])for x in authors]# 第一个作者 与 其他作者链接for author in authors[1:]:
G.add_edge(authors[0],author)# 添加节点2,3并链接23节点
nx.draw(G, with_labels=True)