如何在 Linux Python 中使用 mbcs 编解码器读取 csv 文件?
how to read csv files with mbcs codec in Python on Linux?
我正在尝试使用西欧 (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).
是否有另一个 way/name 可以在 Linux 上解码我在 python 中的文件? (我有上千个文件,所以我无法保存 Excel)
如果您的系统在 Windows 上使用西欧编码,mbcs
编码(ANSI 代码页)是 cp1252
。所以你应该使用:
df = pd.read_csv(FileName,encoding='cp1252', usecols=[1],header=4)
在两个系统上都有兼容的代码库。
我正在尝试使用西欧 (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).
是否有另一个 way/name 可以在 Linux 上解码我在 python 中的文件? (我有上千个文件,所以我无法保存 Excel)
如果您的系统在 Windows 上使用西欧编码,mbcs
编码(ANSI 代码页)是 cp1252
。所以你应该使用:
df = pd.read_csv(FileName,encoding='cp1252', usecols=[1],header=4)
在两个系统上都有兼容的代码库。