Python 3.x UnicodeDecodeError:&x27;ascii';-变通办法
我得到这个错误:Python 3.x UnicodeDecodeError:&x27;ascii';-变通办法,python-3.x,Python 3.x,我得到这个错误: --------------------------------------------------------------------------- UnicodeEncodeError Traceback (most recent call last) <ipython-input-34-8cf38df798b5> in <module>() 1 x = df[['text']] ----&
---------------------------------------------------------------------------
UnicodeEncodeError Traceback (most recent call last)
<ipython-input-34-8cf38df798b5> in <module>()
1 x = df[['text']]
----> 2 x['subjectivity'] = df.text.apply(lambda x: TextBlob(str(unicode(df[['text']]))).sentiment.subjectivity)
3 df.head()
/Users/keenek1/anaconda3/lib/python2.7/site-packages/pandas/core/series.pyc in apply(self, func, convert_dtype, args, **kwds)
3589 else:
3590 values = self.astype(object).values
-> 3591 mapped = lib.map_infer(values, f, convert=convert_dtype)
3592
3593 if len(mapped) and isinstance(mapped[0], Series):
pandas/_libs/lib.pyx in pandas._libs.lib.map_infer()
<ipython-input-34-8cf38df798b5> in <lambda>(x)
1 x = df[['text']]
----> 2 x['subjectivity'] = df.text.apply(lambda x: TextBlob(str(unicode(df[['text']]))).sentiment.subjectivity)
3 df.head()
UnicodeEncodeError: 'ascii' codec can't encode character u'\u2026' in position 551: ordinal not in range(128)
我试着用chardet查找编码
rawdata=open('Tweets.csv',"r").read()
chardet.detect(rawdata)
{'confidence': 0.5471323391929904,
'encoding': 'Windows-1254',
'language': 'Turkish'}
运行时会出现错误
x = df[['text']]
x['subjectivity'] = df.text.apply(lambda x: TextBlob(str(df[['text']])).sentiment.subjectivity)
df.head()
您是否尝试过将字节编码为utf-16或utf-32?能否显示错误的完整回溯,以便我们可以更详细地看到您显示的三条违规行中的哪一部分希望将某些内容解码为ASCII?嘿,感谢您的回答,我已更新了完整错误。我尝试了utf-16和32,但得到了UnicodeDecodeError:“utf32”编解码器无法解码位置0-3的字节:代码点不在范围内(0x110000),因为chardet怀疑编码是“Windows-1254”,您尝试过了吗?我尝试过,但错误没有改变:(您是否尝试将字节编码为utf-16或utf-32?能否显示错误的完整回溯,以便我们可以更详细地看到您显示的三条违规行中的哪一部分希望将某些内容解码为ASCII?嘿,感谢您的回答,我已更新了完整错误。我尝试了utf-16和32,但得到了UnicodeDecodeError:'utf32'编解码器无法解码位置0-3的字节:代码点不在范围内(0x110000),因为chardet怀疑编码是“Windows-1254”,您尝试过了吗?我尝试过,但错误没有改变:(
x = df[['text']]
x['subjectivity'] = df.text.apply(lambda x: TextBlob(str(df[['text']])).sentiment.subjectivity)
df.head()