1

我的代码是:

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)
4

0 回答 0