我试图将一条消息拆分为单独的单词,并尝试对这些消息进行标记。
def split_into_tokens(message):
message = unicode(message, 'utf8') # convert bytes into proper unicode
return TextBlob(message).words
messages.message.head().apply(split_into_tokens)
如果显示名称错误:未定义名称“unicode”
<ipython-input-16-98e123c365b4> in <module>()
----> 1 messages.title.head().apply(split_into_tokens)
C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\series.py in
apply(self, func, convert_dtype, args, **kwds)
3192 else:
3193 values = self.astype(object).values
->3194 mapped = lib.map_infer(values, f,
convert=convert_dtype)
3195
3196 if len(mapped) and isinstance(mapped[0], Series):
pandas/_libs/src\inference.pyx in pandas._libs.lib.map_infer()
<ipython-input-14-281c1d080655> in split_into_tokens(title)
1 def split_into_tokens(title):
----> 2 title = unicode(title, utf8) # convert bytes into proper
unicode
3 return TextBlob(title).words
NameError: name 'unicode' is not defined
最后它显示未定义 unicode,我试图更改 python 版本也仍然是同样的问题。我是否需要在 python 插件目录中用 str 替换 unicode ?
相关分类