赞
踩
##读取.txt并保存为.txt
from jieba import analyse
f = open("result.txt", "w", encoding="utf-8")
for line in open("text.txt",encoding="utf-8"):
tfidf = analyse.extract_tags
text = line
keywords = tfidf(text, topK=4, withWeight=False, allowPOS=())
content_text = ' '.join(keywords)
print(content_text)
f.write(text)
f.write(content_text)
f.write("\n")
f.close()
##读取.xlsx并保存为.xlsx
from jieba import analyse
from openpyxl import load_workbook #导入模块
wb = load_workbook(filename="data.xlsx") # 打开文件, 默认可读写, 若有需要可以指定 write_only和read_only 为True
sheet = wb["Sheet1"] # 找到工作表
for i in range(3,sheet.max_row+1):
text = sheet.cell(row=i, column=2).value
tfidf = analyse.extract_tags
keywords = tfidf(text, topK=4, withWeight=False, allowPOS=())
content_text = " ".join(keywords)
sheet.cell(row=i, column=3, value=content_text)
wb.save('test1.xlsx')
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。