UnicodeDecodeError: 'utf-8' codec can't decode byte 0xf6 in position 125: invalid start byte in R with Reticulate

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xf6 in position 125: invalid start byte in R with Reticulate

大家早上好, 我正在编写一个小脚本来管理 R 中的数据,但是,我不明白为什么当我在 R 中导入一个巨大的 csv (3.5 gb) 文件时,它不起作用。 为了快速解决这个问题,我决定使用 pandasreticulate

#Package from python
pd<-import("pandas", as="pd")
#leggo il file csv con pandas
pd$read_csv("C:\Users\Befrancesco\Desktop\X_dataset\x_file_name.csv, error_bad_lines= FALSE, encoding = "utf-8" )

R returns 我这种类型的错误:

Error in py_call_impl(callable, dots$args, dots$keywords) : 
  UnicodeDecodeError: 'utf-8' codec can't decode byte 0xf6 in position 105: invalid start byte 

我错在哪里了?

提前感谢您的回答。

弗朗切斯科

可能是您的编码不是 UTF-8。在您的 read_csv 调用中尝试一些其他编码,例如 ISO-8859-1,例如

pd$read_csv("C:\Users\Befrancesco\Desktop\X_dataset\x_file_name.csv, error_bad_lines= FALSE, encoding = "ISO-8859-1")

有关不同编码的更多信息,请参阅此答案: