我有一个或多个数据集,我只需要从其中提取计算机科学术语,所以对于这个任务,我必须将我的数据集与list1进行比较。
https://www.aminer.org/oag2019
list1 =‘文件类型’,‘调查和概述’,‘参考著作’,‘大会论文集’,‘传记’,‘一般文献’,‘计算标准,rfcs和指南’,‘交叉计算工具和技术’,......
list1收录的计算机科学术语总数为2112个。
我必须与之进行比较(字符串比较)的数据帧,数据框列中的list1格式为
df_Train14Year‘关键字’.head()
0“核磁共振波谱”,“质谱”,“纳米...1 "plk1",”阳离子二烷基组氨酸“,”晶体s.2“病例对照”,“孩子”,“燃料”,“碳氢化合物”,"... 3 "Ca2+处理“,"CaMKII",”心肌细胞“,”持续...4.
名称:关键字,数据类型:对象
在dataframe中的每个列表中,每个列表中最多有10个关键字min (3),并且dataframe中有数百万条记录。
因此,我必须将每个关键字与原始list1进行比较,如果在两个列表中匹配的单词超过3个,并使用这些值填充数据帧,则可能还需要子字符串匹配。
如何在python中以低效的方式完成这项任务,我所做的是对每个关键字执行for循环,而不是整个列表,其中有三个循环,所以效率很低。
# for i in range(5):
# df.loc[i] = ['<some value for first>','<some value for second>','<some value for third>']
count = 0;
i = 0;
for index, row in df_train14year.iterrows():
# print("index",index)
i=1+1;
# if(i==50):
# break
for outr in row['keywords'].split(","):
#print(count)
if (count>1):
# print("found1")
count = 0;
break;
for inr in computerList:
# outr= outr.replace("[","") # i skip the below three lines because i applied the pre- processing on data to remove the [] and "
# outr= outr.replace("]","")
outr= outr.replace('"',"")
#print("outr",outr,"inr",inr)
if outr in inr:
count = count+1
if (count>10):
#print("outr",outr,"inr",inr)
# print("found2")
# df12.loc[i] = [index,row['keywords']]
#df12.insert(index,"keywords",row['keywords'])
df14_4_match = df14_4_match.append({'abstract': row['abstract'],'keywords': row['keywords'],'title': row['title'],'year': row['year']}, ignore_index=True)
break;
# else:
# print('not found')```发布于 2020-05-04 04:52:52
kewwords =“核磁共振波谱”,“质谱”,"nanos“数据框中的行
预处理:dfk['list_keywords']=[[x for x in j.split('[')[1].split(']')[0].split('"')[1:-1] if x not in[',',' , ',', ']] for j in dfk['keywords']]
将orgional list转换为set后
dfk['set_keywords']=dfk['list_keywords'].map(lambda x: set(x))
我们比较上述关键字列表和计算机列表(List1)的交集,以获得匹配的项数或关键字
dfk['set_keywords']=dfk['set_keywords'].map(lambda x:x.intersection(proceseedComputerList))
使用此函数获取长度
dfk['len_keywords']=dfk['set_keywords'].map(lambda x:len(x))
按升序排序
dfk.head()```https://stackoverflow.com/questions/61456580
复制相似问题