2016-09-04 1 views
0

팬더에서 POS를 추출하고 싶습니다. 나는AttributeError : 'list'객체에 'isdigit'속성이 없습니다.

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

아래와 같이 할 수 있지만, 역 추적 얻을 :

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' 

문제점은 무엇입니까? . isdigitstr하는 방법이기 때문에

답변

2

:.

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

인쇄물 :

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

표현 s.str.split() 문자열의 list이다가 아니라 문자열 (pos_tag 예상 당신은 실제로 직접 pos_tag() 방법에 Series 개체를 전달할 수

+1

실제로는 아닙니다. ndas'Series' 인스턴스. 각 * column *은 문자열 목록입니다. –

+0

좋아, 목록처럼 보입니다. 실수해서 미안해. –

+0

OP는 역 추적을 포함하지 않으므로 이해할 수 있으며 식 *이 원인입니다. 네가 말하는 이유 때문 만은 아니야. –

관련 문제