我制作了一个 250MB 的 json 文件,它应该是这样的:
[ {"A":"uniquevalue0", "B":[1,2,3]},
{"A":"uniquevalue1", "B":[1]},
{"A":"uniquevalue2", "B":[1,2,3,4]} ]
其中“B”值可以是变量 len >= 1。This说我有有效的 JSON。
我打电话
df = pandas.read_json('ut1.json', orient = 'records', dtype={"A":str, "B":list})
Here是文档。读入 Pandas 数据帧时,我得到以下回溯:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/.../pandas/io/json.py", line 198, in read_json
date_unit).parse()
File "/.../pandas/io/json.py", line 266, in parse
self._parse_no_numpy()
File "/.../pandas/io/json.py", line 496, in _parse_no_numpy
loads(json, precise_float=self.precise_float), dtype=None)
ValueError: Unexpected character found when decoding 'true'
想不出哪里出了问题。 The python file that is throwing the error不是很有帮助。
最佳答案
我有同样的错误信息,我通过使用绝对路径解决了它。
import os
basePath = os.path.dirname(os.path.abspath(__file__))
df = pandas.read_json(basePath + '/ut1.json', orient = 'records', dtype={"A":str, "B":list})
这对我有用!
关于python - 使用 pandas.read_json 时出现 ValueError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27240982/