2014-12-02 62 views
2

当我做了一个250MB的JSON文件看起来应该像这样的:ValueError异常使用pandas.read_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是文档。当读入熊猫数据帧时,我得到以下回溯:

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不是那么有用。

+0

该代码与给定的json文件完美配合。 – falsetru 2014-12-02 02:44:04

回答

4

我有相同的错误信息,我通过使用绝对路径解决了它。

import os 
basePath = os.path.dirname(os.path.abspath(__file__)) 
df = pandas.read_json(basePath + '/ut1.json', orient = 'records', dtype={"A":str, "B":list}) 

这对我有效!