1

My code is:

from polyglot.text import Text

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


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

df2 is a panda data frame read from a huge csv file containing sentences from almost all languages. The code returns the following error. I tried reading the csv using "encoding='utf-8'" option but it didn't work. Any idea how to fix this?


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)

0 Answers0