我正在使用Python 3.6.1(IDLE)并计算pos_tag的频率。我的代码是
import csv
import nltk
with open('data.csv', 'rt') as f:
readerf = csv.reader(f)
from collections import Counter
Counter([j for i,j in pos_tag(row)])
我收到以下错误消息
Traceback (most recent call last):
File "C:/Users/ABRAR/Google Drive/Tourism Project/TouristPython/POS_Tagging.py", line 7, in <module>
Counter([j for i,j in pos_tag(row)])
NameError: name 'row' is not defined
但是,相同的代码在jupyter(基于Web)中正确运行。 这是我的样本数据
[AB, 一下, 放弃, 减弱, ABC, 能力, 能够, 沐浴, 盛产, 国外, 突然, 缺席, 绝对, 绝对, 吸收
这是jupyter的快照 code and answer
答案 0 :(得分:1)
import csv
import nltk
f = open("data.csv","r")
readerf = csv.reader(f)
temp = []
for row in readerf:
temp.append(postag(row)[1])
from collections import Counter
Counter(temp)
我认为这将解决您的问题