with open('C:\\Users\\lvhao\\Desktop\\test.txt','r') as f:
dic = {}
for line in f:
listlist = line.split(' ')
#print(listlist[1])
if '著' in listlist[1]:
listlist[1] = listlist[1].split('著')
dic[listlist[0]] = listlist[1][0]
elif '编' in listlist[1]:
listlist[1] = listlist[1].split('编')
dic[listlist[0]] = listlist[1][0]
elif '摄' in listlist[1]:
listlist[1] = listlist[1].split('摄')
dic[listlist[0]] = listlist[1][0]
elif '主编' in listlist[1]:
listlist[1] = listlist[1].split('主编')
dic[listlist[0]] = listlist[1][0]
elif '[著]' in listlist[1]:
listlist[1] = listlist[1].split('[著]')
dic[listlist[0]] = listlist[1][0]
elif '撰' in listlist[1]:
listlist[1] = listlist[1].split('撰')
dic[listlist[0]] = listlist[1][0]
elif '访谈' in listlist[1]:
listlist[1] = listlist[1].split('访谈')
dic[listlist[0]] = listlist[1][0]
elif '主编' in listlist[1]:
listlist[1] = listlist[1].split('主编')
dic[listlist[0]] = listlist[1][0]
elif '口述' in listlist[1]:
listlist[1] = listlist[1].split('口述')
dic[listlist[0]] = listlist[1][0]
elif '[著]' in listlist[1]:
listlist[1] = listlist[1].split('[著]')
dic[listlist[0]] = listlist[1][0]
elif '[绘]' in listlist[1]:
listlist[1] = listlist[1].split('[绘]')
dic[listlist[0]] = listlist[1][0]
elif '原著' in listlist[1]:
listlist[1] = listlist[1].split('原著')
dic[listlist[0]] = listlist[1][0]
elif '主' in listlist[1]:
listlist[1] = listlist[1].split('主')
dic[listlist[0]] = listlist[1][0]
else:
dic[listlist[0]] = ''
with open('C:\\Users\\lvhao\\Desktop\\test2.xlsx','w') as f:
for key, value in dic.items():
print(key, value)
f.write(key+'\t'+value+"\n")
# df = pd.DataFrame(dic)
# df.to_excel('C:\\Users\\lvhao\\Desktop\\test3.xlsx')
处理数据,把作者名字提取出来
最新推荐文章于 2023-06-21 03:00:41 发布