简体   繁体   English

AttributeError:“列表”对象没有属性“ isdigit”

[英]AttributeError: 'list' object has no attribute 'isdigit'

I want to extract POS in pandas. 我想提取熊猫中的POS。 I do as below 我做如下

import pandas as pd
from nltk.tag import pos_tag
df = pd.DataFrame({'pos': ['noun', 'Alice', 'good', 'well', 'city']})
s = df['pos']
tagged_sent = pos_tag(s.str.split())

but get a traceback: 但是得到一个追溯:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "../lib/python2.7/site-packages/nltk/tag/__init__.py", line 111, in pos_tag
    return _pos_tag(tokens, tagset, tagger)
  File "../lib/python2.7/site-packages/nltk/tag/__init__.py", line 82, in _pos_tag
    tagged_tokens = tagger.tag(tokens)
  File "/Users/mjpieters/Development/venvs/stackoverflow-2.7/lib/python2.7/site-packages/nltk/tag/perceptron.py", line 152, in tag
    context = self.START + [self.normalize(w) for w in tokens] + self.END
  File "../lib/python2.7/site-packages/nltk/tag/perceptron.py", line 224, in normalize
    elif word.isdigit() and len(word) == 4:
AttributeError: 'list' object has no attribute 'isdigit'

What's wrong? 怎么了?

You can actually pass Series object to the pos_tag() method directly: 实际上,您可以直接将Series对象传递给pos_tag()方法:

s = df['pos']
tagged_sent = pos_tag(s)  # or pos_tag(s.tolist())
print(tagged_sent)

Prints: 打印:

[('noun', 'JJ'), ('Alice', 'NNP'), ('good', 'JJ'), ('well', 'RB'), ('city', 'NN')]

表达式s.str.split()是一个字符串list ,而不是字符串(由pos_tag期望。),因为isdigitstr一种方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 AttributeError:&#39;int&#39;对象没有属性&#39;isdigit&#39; - AttributeError: 'int' object has no attribute 'isdigit' AttributeError: 'generator' object 没有属性 'isdigit' - AttributeError: 'generator' object has no attribute 'isdigit' AttributeError: &#39;int&#39; 对象没有属性 &#39;isdigit&#39; 和 NameError - AttributeError: 'int' object has no attribute 'isdigit' and NameError Python-AttributeError:“ str”对象没有属性“ isDigit” - Python - AttributeError: 'str' object has no attribute 'isDigit' Python AttributeError:“系列”对象没有属性“ isdigit” - Python AttributeError: 'Series' object has no attribute 'isdigit' AttributeError: &#39;list&#39; 对象没有属性 &#39;isdigit&#39; 从找到的数据中提取数字 - AttributeError: 'list' object has no attribute 'isdigit' extract numbers from data that is found 为什么我的代码不起作用 AttributeError: 'int' object has no attribute 'isdigit' - why my code not working AttributeError: 'int' object has no attribute 'isdigit' AttributeError:&#39;int&#39;对象没有用户输入的属性&#39;isdigit&#39; - AttributeError: 'int' object has no attribute 'isdigit' from user input AttributeError&#39;int&#39;对象在Ubuntu中的ipython中没有属性isdigit - AttributeError 'int' object has no attribute isdigit in ipython in ubuntu attributeError: 'list' object 没有属性..... - attributeError: 'list' object has no attribute.....
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM