名称:name' row'未定义

发布于 2025-02-04 08:01:51 字数 738 浏览 3 评论 0原文

我正在使用Python 3.6.1(空闲)和计算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的快照 代码和答案

I am using the Python 3.6.1(IDLE) and counting the frequency of the pos_tag. My code is

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)])

I am getting the following error message

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

However,the same code run correctly in the jupyter(web based).
Here is my sample data

[ab,
aback,
abandon,
abate,
abc,
ability,
able,
ablution,
abound,
abroad,
abruptly,
absence,
absolute,
absolutely,
absorb]

and here is the snap of jupyter
code and answer

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

独﹏钓一江月 2025-02-11 08:01:51
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)

我认为这将解决您的问题

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)

I think this will solve your problem

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文