【问题标题】:There is no proper solution available for "utf-8' codec can't decode byte 0x99 in position 21" [duplicate]“utf-8”编解码器无法解码位置 21 的字节 0x99”没有合适的解决方案 [重复]
【发布时间】:2018-11-05 11:00:44
【问题描述】:

目前坚持使用具有 10lac 行的 .csv 文件。我正在将数据集加载到名为 rawdata 的数据框架 Python 中。该文件有 ascii 代码可能是因为它拍摄错误 'utf-8' codec can't decode byte 0x99 in position 21: invalid start byte 任何地方都没有正确提及此问题的解决方案。 在此输入代码

将 numpy 导入为 np 将熊猫导入为 pd 将 scipy 导入为 sci

导入系统 重新加载(系统) sys.setdefaultencoding("ISO-8859-1")

导入操作系统 打印 os.getcwd()

os.chdir('D:\DJ\展示位置报告\')

setwd()

rawdata=pd.read_csv('D:\DJ\Placement reports\Copy of Placement Reports _ Apr_Mar_May Page 2.csv', newline='', encoding='utf-8')

rawdata=pd.read_csv("D:\DJ\Placement reports\Copy of Placement Reports _ Apr_Mar_May Page 1.csv")

rawdata=pd.read_csv("D:\DJ\Pyhton analysis\wagering.csv")

a.encode('utf-8').strip()

x = pd.read_csv("D:\DJ\Placement reports\Test1.csv")

open('D:\DJ\Placement reports\Copy of Placement Reports _ Apr_Mar_May Page 2.csv', newline='', encoding='utf-8')

数据框:: 月展示位置 展示位置 URL 类型 广告系列 广告组点击次数 展示次数点击率平均每次点击费用 Apr-18 移动应用程序:Cric Informer(Dream11,Myteam11 Tips & IPL NEWS) (Google Play), by BRAJ & GEETA INC https://play.google.com/store/apps/details?id=manager.attendance.fantasycrickettips 移动应用程序 Display-Affinity-Keyword-Topics Display_Keywords 52,584 61,07,340 0.86% ? 1.76 ? 92,484.03 3 月 18 日移动应用程序:NewsDog - 最新消息、突发新闻、本地新闻 (Google Play),由 NewsDog 团队 https://play.google.com/store/apps/details?id=com.newsdog 移动应用程序 Display-Affinity-Keyword-Topics Audience_Affinity 99,361 58,55,703 1.70% ? 0.82 ? 81,644.29 Apr-18 移动应用程序:Cric Informer(Dream11,Myteam11 Tips & IPL NEWS) (Google Play), by BRAJ & GEETA INC https://play.google.com/store/apps/details?id=manager.attendance.fantasycrickettips 移动应用程序 Display-Custom-Intent-India Custom-Intent 28,106 43,14,179 0.65% ? 2.85 ? 79,991.28 Apr-18 移动应用程序:Cric Informer(Dream11,Myteam11 Tips & IPL NEWS) (Google Play), by BRAJ & GEETA INC https://play.google.com/store/apps/details?id=manager.attendance.fantasycrickettips 移动应用程序 Display-Affinity-Keyword-Topics Audience_Affinity 39,526 39,54,727 1.00% ? 1.79 ? 70,662.24 Apr-18 us.com http://us.com Site Display-Affinity-Keyword-Topics Audience_Affinity 23,792 60,06,433 0.40% ? 2.83 ? 67,301.35 3 月 18 日移动应用程序:GiftMoney (Google Play),由 KingToUpper https://play.google.com/store/apps/details?id=com.akp151998.giftmoney 移动应用程序 Display-Affinity-Keyword-Topics Audience_Affinity 27,012 3,15,541 8.56% ? 2.47 ? 66,765.34 4 月 18 日移动应用程序:mCent 浏览器 - Fast and Safe plus Free Data (Google Play), by mCent https://play.google.com/store/apps/details?id=com.mcent.browser 移动应用程序 Display-Affinity-Keyword-Topics Display_Keywords 31,898 56,07,897 0.57% ? 1.77 ? 56,368.85 Apr-18 移动应用程序:Cric Informer(Dream11,Myteam11 Tips & IPL NEWS) (Google Play), by BRAJ & GEETA INC https://play.google.com/store/apps/details?id=manager.attendance.fantasycrickettips 移动应用程序 Display-Affinity-Keyword-Topics Display_Keywords 52,584 61,07,340 0.86% ? 1.76 ? 92,484.03

我已经尝试了所有这些步骤来解决,但都失败了。请帮助提供解决方案或链接。 请转换成 CSV 格式

【问题讨论】:

  • 代码格式丢失,问题现在难以阅读。

标签: python pandas data-science data-science-experience code-analyst


【解决方案1】:

试试a.encode('utf-8', 'ignore')。这应该只是删除所有无效字节。

【讨论】:

  • 可能是python中的数据框。但在这种情况下,pyhton 无法读取或加载数据。如何读取包含此 ascii 代码的文件。
猜你喜欢
  • 2019-05-07
  • 2019-08-02
  • 1970-01-01
  • 1970-01-01
  • 2020-07-17
  • 2019-11-10
  • 1970-01-01
  • 2021-02-07
  • 2021-08-29
相关资源
最近更新 更多