多语言 >> 错误:输入在字节 35共 62 个附近包含无效的 UTF-8

问题描述

我的代码是:

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)

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...