from textblob import TextBlob
import pandas as pd
import nltk
nltk.download('averaged_perceptron_tagger')
Idea=pd.read_csv(r"E:\1.csv",encoding="utf-8")
i=len(Idea)
print(i)
content=[]
content
for x in range(0,i):
j=Idea['Summary'][x]
blob=TextBlob(j)
tag=blob.tags
content.append([tag])
dd=pd.DataFrame(content,columns=['tag'])
dd.to_csv(r"E:\tag.csv")
'''
将结果分开
'''
import openpyxl
from collections import Counter
import csv
wb = openpyxl.load_workbook(r"E:/tag.xlsx")
wb = wb.active
for i in range(2, 27):
a = eval(wb.cell(row=i, column=2).value)
list = []
for tag in a:
list.append(tag[1])
res = Counter(list)
res = dict(res)
with open("E:/NLTK.txt", mode='r', encoding='utf-8') as f:
nltk = eval(f.read())
for key in res.keys():
nltk[key] = res[key]
with open("E:/tagCount1.csv", mode='a', encoding='utf-8', newline='') as f1:
csv_writer1 = csv.writer(f1)
csv_writer1.writerow(nltk.values())
print(i)
|