UnicodeDecodeError: 'utf-8' codec can't decode byte
UnicodeDecodeError: 'utf-8' codec can't decode byte
无法为我的商业智能加载此数据集 class。我尝试了一个不同的 csv 文件并且有效。尝试用谷歌搜索一些解决方案,但无法弄清楚。任何帮助将不胜感激!
# load data
col_names = ['age', 'gender', 'coffee_bags_bought', 'spent_last_week', 'spent_last_month', 'income', 'online', 'new_product']
# load dataset
coffeeStore = pd.read_csv("/content/CoffeeStore.xlsx", header=None, names=col_names)
coffeeStore.head(2)
这是我 运行 遇到的错误:
---------------------------------------------------------------------------
UnicodeDecodeError Traceback (most recent call last)
<ipython-input-35-e3969313ee59> in <module>()
3 col_names = ['age', 'gender', 'coffee_bags_bought', 'spent_last_week', 'spent_last_month', 'income', 'online', 'new_product']
4 # load dataset
----> 5 coffeeStore = pd.read_csv("/content/CoffeeStore.xlsx", header=None, names=col_names)
6 coffeeStore.head(2)
9 frames
/usr/local/lib/python3.7/dist-packages/pandas/_libs/parsers.pyx in pandas._libs.parsers.raise_parser_error()
UnicodeDecodeError: 'utf-8' codec can't decode bytes in position 15-16: invalid continuation byte
您在 excel 文件上使用 read_csv
。使用 read_excel
代替
coffeeStore = pd.read_excel("/content/CoffeeStore.xlsx", header=None, names=col_names)
您也可以将引擎参数更改为'python'
coffeeStore = pd.read_csv("/content/CoffeeStore.xlsx", header=None, names=col_names,engine='python')
有关 unicode、utf-8 等的更多详细说明,请阅读 this legendary blog post
无法为我的商业智能加载此数据集 class。我尝试了一个不同的 csv 文件并且有效。尝试用谷歌搜索一些解决方案,但无法弄清楚。任何帮助将不胜感激!
# load data
col_names = ['age', 'gender', 'coffee_bags_bought', 'spent_last_week', 'spent_last_month', 'income', 'online', 'new_product']
# load dataset
coffeeStore = pd.read_csv("/content/CoffeeStore.xlsx", header=None, names=col_names)
coffeeStore.head(2)
这是我 运行 遇到的错误:
---------------------------------------------------------------------------
UnicodeDecodeError Traceback (most recent call last)
<ipython-input-35-e3969313ee59> in <module>()
3 col_names = ['age', 'gender', 'coffee_bags_bought', 'spent_last_week', 'spent_last_month', 'income', 'online', 'new_product']
4 # load dataset
----> 5 coffeeStore = pd.read_csv("/content/CoffeeStore.xlsx", header=None, names=col_names)
6 coffeeStore.head(2)
9 frames
/usr/local/lib/python3.7/dist-packages/pandas/_libs/parsers.pyx in pandas._libs.parsers.raise_parser_error()
UnicodeDecodeError: 'utf-8' codec can't decode bytes in position 15-16: invalid continuation byte
您在 excel 文件上使用 read_csv
。使用 read_excel
代替
coffeeStore = pd.read_excel("/content/CoffeeStore.xlsx", header=None, names=col_names)
您也可以将引擎参数更改为'python'
coffeeStore = pd.read_csv("/content/CoffeeStore.xlsx", header=None, names=col_names,engine='python')
有关 unicode、utf-8 等的更多详细说明,请阅读 this legendary blog post