Unicodedecodeerror:' utf-8'编解码器可以解码字节
在此数据集中为我的商业智能类加载困难。我尝试了另一个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
Having trouble loading in this dataset for my Business Intelligence class. I tried a different csv file and that worked. Tried googling some solutions but couldn't figure it out. Any help would be greatly appreciated!
# 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)
This is the error I'm running into:
---------------------------------------------------------------------------
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您还可以将引擎参数更改为“ Python”,
以获取有关Unicode,utf-8等的更详细说明。阅读此传奇的博客文章
You can also change engine parameter to 'python'
For more detailed explanation about unicode, utf-8 etc. read this legendary blog post
您正在Excel文件上使用
read_csv
。使用read_excel
而不是You're using
read_csv
on an excel file. Useread_excel
instead