我正在尝试读取使用西欧(windows)编码的CSV文件
df = pd.read_csv(FileName,encoding='mbcs', usecols=[1],header=4)
这段代码在Windows上工作得很好,但在Linux 18.04上就不行了。(错误:未知编码: mbcs)实际上,在codecs python documentation中,我们有以下信息:
mbcs is for Windows only: Encode the operand according to the ANSI codepage (CP_ACP).
在Linux上有没有其他方法/name来解码我的python文件?(我有上千个文件,所以我不能保存在Excel上)
发布于 2020-04-28 22:02:42
如果您的系统在Windows上使用西欧编码,则mbcs
编码(ANSI代码页)为cp1252
。所以你应该使用:
df = pd.read_csv(FileName,encoding='cp1252', usecols=[1],header=4)
在两个系统上都有一个兼容的代码库。
https://stackoverflow.com/questions/61481806
复制相似问题