pandas UnicodeDecodeError: 'utf-8' 编解码器无法解码位置 0-1 中的字节:继续字节无效
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/55193168/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
UnicodeDecodeError: 'utf-8' codec can't decode bytes in position 0-1: invalid continuation byte
提问by Ambleu
I am trying to try pandas methods in a csv file I've made which looks like:
我正在尝试在我制作的 csv 文件中尝试 Pandas 方法,该文件如下所示:
Location Time Number
Seoul Nov.11 5
Jinju dec.22 2
wpg 3
june.6 2
something like this. It is giving me an error message in the title. How can I fix this and what position is it referring exactly?
像这样的东西。它在标题中给了我一条错误消息。我该如何解决这个问题,它究竟指的是什么位置?
回答by taipei
according to https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.read_csv.html, you can add encoding parameter when read the csv file. I suggest you to add "utf-8" or "ISO-8859-1". pandas.read_csv(yourfile, encoding="utf-8") or pandas.read_csv(yourfile, encoding="ISO-8859-1")
根据https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.read_csv.html,您可以在读取 csv 文件时添加编码参数。我建议您添加“utf-8”或“ISO-8859-1”。pandas.read_csv(yourfile, encoding="utf-8") 或 pandas.read_csv(yourfile, encoding="ISO-8859-1")