python - Python SyntaxError:非 ASCII 字符
问题描述
我的熊猫数据框中有一个字符串列。当我尝试将此列导出到 Excel 文件时,我遇到了错误。如果我删除该列,我能够导出数据框。
我试图解码该字符串列中的所有值。我收到以下错误:
UnicodeDecodeError: 'ascii' codec can't decode byte 0x81 in position 16: ordinal not in range(128)
我调试了一下,在那个特定的列中找到了一个列值。我无法解码这个值('Einen Use case fr Brems-')。
我采用了该值并尝试了以下代码,再次遇到错误。
#!/usr/bin/python
# -*- coding: utf-8 -*-
text = 'Einen Use case fr Brems-'
print text.decode()
1)我也尝试添加以下行。
import sys
reload(sys)
sys.setdefaultencoding('utf8')
2)我在我的系统中试过这个:
import sys
print sys.getdefaultencoding()
我得到'ascii'作为输出。
解决方案
推荐阅读
- javascript - Javascript:获取每个分号分隔的子字符串的第一个数字子字符串
- c# - 将文件上传到谷歌驱动器
- java - Swing 应用程序窗口未显示更改
- android - 如何使 LinearLayout 中的 TextView 填充剩余空间并被截断
- java - 当我按下开始按钮时,它应该进入下一个活动,但它会进入主屏幕
- rust - Rust 中 Vec 的内存布局是怎样的?
- python - google-coud-storage python list_blob 性能
- activemq - 如何修复错误 activeMQ 端口已在使用中
- c# - C# 从 FTP 下载/读取日志文件
- javascript - 正则表达式:键入的单词匹配开头还是整个单词?