【问题标题】:Unable to load Sentihood dataset Json file in Python无法在 Python 中加载 Sentihood 数据集 Json 文件
【发布时间】:2019-09-09 17:08:50
【问题描述】:

情感数据集是基于目标方面的情感分析的数据集。其测试和训练文件以 Json 格式提供。但是,当我尝试使用 python 的 json 模块加载它时,它会给出以下错误-

JSONDecodeError:预期值:第 7 行第 1 列(字符 6)

还有其他加载 Json 文件的方法吗?我对 Json 了解不多,因此希望得到任何帮助。 Sentihood 数据集链接:https://github.com/uclmr/jack/tree/master/data/sentihood

我的代码很简单:

with open("sentihood-train.json", "r") as read_it: 
    data = json.load(read_it)

【问题讨论】:

  • 你确定你下载的文件是正确的并且sentihood-train.json是和github repo中的完全相同的文件吗?它应该大约 1MB 大。
  • 检查了 train 和 test json 都在我的情况下工作。

标签: python json python-3.x nlp sentiment-analysis


【解决方案1】:

读取文件时 json.loads 需要文件内容,可以通过以下方式完成。在 json.loads 行中传递 f.read()

import json
with open("test.json",mode='r') as f:
    d = json.loads(f.read())  # changed this line
    print(d)

【讨论】:

  • 这与@Dornish 使用的代码基本相同。
猜你喜欢
  • 2020-09-29
  • 2017-01-06
  • 2020-04-06
  • 2021-04-04
  • 1970-01-01
  • 1970-01-01
  • 2017-06-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多