当我尝试在 python 中导入时,.csv 文件返回 "unicode error"
.csv file is returning a "unicode error" when I attempt to import in python
我正在尝试在 Jupyter 笔记本上使用 pandas 导入 .csv 数据集文件。我不断收到相同的 "unicode decode error" 消息
我试过使用和不使用 (r'file name')
并加倍使用反斜杠,以及使用正斜杠
这是我的代码
import pandas as pd
df = pd.read_csv(r'C:\users\justanotheregg\Downloads\medals.csv')
这是我收到的一部分
UnicodeDecodeError Traceback (most recent call last)
pandas/_libs/parsers.pyx in pandas._libs.parsers.TextReader._convert_tokens()
pandas/_libs/parsers.pyx in pandas._libs.parsers.TextReader._convert_with_dtype()
pandas/_libs/parsers.pyx in pandas._libs.parsers.TextReader._string_convert()
pandas/_libs/parsers.pyx in pandas._libs.parsers._string_box_utf8()
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x92 in position 12: invalid start byte
During handling of the above exception, another exception occurred:
您的 CSV 文件显然不在 UTF-8 format, but that is what the function expects by default. You need to find out what encoding the file is in (if it is an Excel export, it's probably 'cp-1252'; the other likely encodings, from the ISO-8859 family, don't have a mapping for 0x92, where it's the closing single quote ’
in 1252, very common in text written in MS Office) and pass its name as the optional encoding parameter。
我遇到了同样的问题。
刚刚保存到google张,然后下载了同样的文件,熊猫在jupyter notebook中阅读就ok了。
我正在尝试在 Jupyter 笔记本上使用 pandas 导入 .csv 数据集文件。我不断收到相同的 "unicode decode error" 消息
我试过使用和不使用 (r'file name')
并加倍使用反斜杠,以及使用正斜杠
这是我的代码
import pandas as pd
df = pd.read_csv(r'C:\users\justanotheregg\Downloads\medals.csv')
这是我收到的一部分
UnicodeDecodeError Traceback (most recent call last)
pandas/_libs/parsers.pyx in pandas._libs.parsers.TextReader._convert_tokens()
pandas/_libs/parsers.pyx in pandas._libs.parsers.TextReader._convert_with_dtype()
pandas/_libs/parsers.pyx in pandas._libs.parsers.TextReader._string_convert()
pandas/_libs/parsers.pyx in pandas._libs.parsers._string_box_utf8()
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x92 in position 12: invalid start byte
During handling of the above exception, another exception occurred:
您的 CSV 文件显然不在 UTF-8 format, but that is what the function expects by default. You need to find out what encoding the file is in (if it is an Excel export, it's probably 'cp-1252'; the other likely encodings, from the ISO-8859 family, don't have a mapping for 0x92, where it's the closing single quote ’
in 1252, very common in text written in MS Office) and pass its name as the optional encoding parameter。
我遇到了同样的问题。
刚刚保存到google张,然后下载了同样的文件,熊猫在jupyter notebook中阅读就ok了。