【问题标题】:Unmatched ''"' when when decoding 'string' error in reading json file into pandas dataframe将json文件读入pandas数据帧时解码'string'错误时出现不匹配的''"'
【发布时间】:2018-10-09 11:41:41
【问题描述】:

我正在尝试使用 pd.read_json() 将亚马逊评论数据加载到 pandas 数据帧中,这是一个 JSON 文件,我收到以下错误 Unmatched ''"' when when decoding 'string'.我正在使用 jupyter notebook

数据格式:

{"reviewerID": "AGL65XWV7MH3C", "asin": "B003FMUVKO", "reviewerName": "William B. Bebout \"Acknud\"", "helpful": [0, 1], "reviewText": "Too short. I would have rated it higher if it was long enough to hold my attention! It did have significant violence but not much else.", "overall": 3.0, "summary": "Short", "unixReviewTime": 1304985600, "reviewTime": "05 10, 2011"}

Python 代码:

data =pd.read_json('sample_data.json', lines=True)

【问题讨论】:

  • @GeneBurinsky:我如何重新格式化它?,我刚刚显示了一行数据,在我的实际文件中,我有 1000 行
  • 您的代码在我的笔记本电脑上运行良好
  • 可能是您缺少转义反斜杠吗?尝试用“\\”替换所有“\”。
  • 我用更少的行数执行了相同的代码,它对我有用,
  • 这是数据错误,还是有办法使用 json.load() 参数解决?我遇到了同样的错误。

标签: python pandas jupyter-notebook


【解决方案1】:

我只是遇到了同样的错误,在尝试了所有可能的解决方案后,简单的解决方法是删除文件末尾的空行。

在文件末尾留一个空行是一种常见的约定,但由于某种原因似乎让 pandas 窒息,

【讨论】:

    猜你喜欢
    • 2021-12-30
    • 1970-01-01
    • 1970-01-01
    • 2016-05-26
    • 2014-01-21
    • 2019-08-13
    • 1970-01-01
    • 1970-01-01
    • 2022-08-16
    相关资源
    最近更新 更多