【发布时间】:2019-07-15 20:51:27
【问题描述】:
我正在尝试在数据框的列中应用 RegexpTokenizer。
数据框:
all_cols
0 who is your hero and why
1 what do you do to relax
2 can't stop to eat
4 how many hours of sleep do you get a night
5 describe the last time you were relax
脚本:
import re
import nltk
import pandas as pd
from nltk import RegexpTokenizer
#tokenization of data and suppression of None (NA)
df['all_cols'].dropna(inplace=True)
tokenizer = RegexpTokenizer("[\w']+")
df['all_cols'] = df['all_cols'].apply(tokenizer)
错误:
TypeError: 'RegexpTokenizer' 对象不可调用
但我不明白。当我使用另一种 nltk 标记化模式 word_tokenize 时,效果很好......
【问题讨论】: