结巴分词时,AttributeError: 'DataFrame' object has no attribute 'decode',

img


到这里都没有问题。

img


出现问题描述


AttributeError                            Traceback (most recent call last)
<ipython-input-45-6c75e3b0fd1c> in <module>
      2 
      3 jieba.load_userdict(dict) # dict为自定义词典的路径
----> 4 '/'.join(jieba.cut(ecom_info))

C:\ProgramData\Anaconda3\lib\site-packages\jieba\__init__.py in cut(self, sentence, cut_all, HMM, use_paddle)
    298         """
    299         is_paddle_installed = check_paddle_install['is_paddle_installed']
--> 300         sentence = strdecode(sentence)
    301         if use_paddle and is_paddle_installed:
    302             # if sentence is null, it will raise core exception in paddle.

C:\ProgramData\Anaconda3\lib\site-packages\jieba\_compat.py in strdecode(sentence)
     77     if not isinstance(sentence, text_type):
     78         try:
---> 79             sentence = sentence.decode('utf-8')
     80         except UnicodeDecodeError:
     81             sentence = sentence.decode('gbk', 'ignore')

C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\generic.py in __getattr__(self, name)
   5463             if self._info_axis._can_hold_identifiers_and_holds_name(name):
   5464                 return self[name]
-> 5465             return object.__getattribute__(self, name)
   5466 
   5467     def __setattr__(self, name: str, value) -> None:

AttributeError: 'DataFrame' object has no attribute 'decode'

jieba的cut方法,接受的参数为str类型,而你的参数ecom_info是一个dataframe。你应该先将ecom_info转换为str类型才可以,或者用apply对dataframe具体的值应用jieba的cut方法
有帮助,望采纳。