我试图在数据帧的一列中应用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' object is not callable
但我不明白。当我使用另一个nltk标记化模式时,word\u tokenize可以完美地工作。。。你知道吗
首先要删除缺少的值,必须使用^{} 和指定列名,然后使用
tokenizer.tokenize
方法,因为您的解决方案不会删除缺少的值:请注意,在调用} 方法:
RegexpTokenizer
时,只需使用一组参数创建类的实例(调用其__init__
方法)。 为了用指定的模式实际标记dataframe列,必须调用其^{相关问题 更多 >
编程相关推荐