0

我正在尝试使用西欧(Windows)编码读取 CSV 文件

df = pd.read_csv(FileName,encoding='mbcs', usecols=[1],header=4)

此代码在 Windows 上运行良好,但在 Linux 18.04 上运行良好。(错误:未知编码:mbcs)确实,在编解码器python文档中,我们有信息:

mbcs is for Windows only: Encode the operand according to the ANSI codepage (CP_ACP).

是否有另一种方法/名称可以在 Linux 上的 python 中解码我的文件?(我有数千个文件,所以我无法在 Excel 上另存为)

4

1 回答 1

1

如果您的系统在 Windows 上使用西欧编码,则mbcs编码(ANSI 代码页)为cp1252. 所以你应该使用:

df = pd.read_csv(FileName,encoding='cp1252', usecols=[1],header=4)

在两个系统上都有一个兼容的代码库。

于 2020-04-28T14:02:41.873 回答