Polyglot>>错误:输入在字节35(共62个)周围包含无效UTF8

2024-10-02 00:39:12 发布

您现在位置:Python中文网/ 问答频道 /正文

我的代码是:

from polyglot.text import Text

def getPolyglotPolarity(text):
 return Text(text).polarity


df['PolyPolarity']=df2.apply(getPolyglotPolarity)

df2是从包含几乎所有语言句子的巨大csv文件读取的熊猫数据帧。代码返回以下错误。我尝试使用“encoding='utf-8'”选项读取csv,但没有成功。你知道怎么解决这个问题吗


error                                     Traceback (most recent call last)
<ipython-input-67-a4c61d6289ae> in <module>
      4 
      5 
----> 6 df['PolyPolarity']=df2.apply(getPolyglotPolarity)

C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\series.py in apply(self, func, convert_dtype, args, **kwds)
   4198             else:
   4199                 values = self.astype(object)._values
-> 4200                 mapped = lib.map_infer(values, f, convert=convert_dtype)
   4201 
   4202         if len(mapped) and isinstance(mapped[0], Series):

pandas\_libs\lib.pyx in pandas._libs.lib.map_infer()

<ipython-input-67-a4c61d6289ae> in getPolyglotPolarity(text)
      1 #polyglot
      2 def getPolyglotPolarity(text):
----> 3  return Text(text).polarity
      4 
      5 

C:\ProgramData\Anaconda3\lib\site-packages\polyglot\decorators.py in __get__(self, obj, cls)
     18     if obj is None:
     19         return self
---> 20     value = obj.__dict__[self.func.__name__] = self.func(obj)
     21     return value
    

C:\ProgramData\Anaconda3\lib\site-packages\polyglot\detect\base.py in detect(self, text)
     82     """
     83     t = text.encode("utf-8")
---> 84     reliable, index, top_3_choices = cld2.detect(t, bestEffort=False)
     85 
     86     if not reliable:

error: input contains invalid UTF-8 around byte 35 (of 62)

Tags: textinselfobjinputreturnlibsite

热门问题