2014-12-02 214 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}) 

這對我有效!