2017-05-31 44 views
2

樣本數據ValueError異常:預期對象或值讀取時JSON作爲熊貓數據幀

{ 
    "_id": "OzE5vaa3p7", 
    "categories": [ 
     { 
     "__type": "Pointer", 
     "className": "Category", 
     "objectId": "nebCwWd2Fr" 
     } 
    ], 
    "isActive": true, 
    "imageUrl": "https://firebasestorage.googleapis.com/v0/b/shopgro-1376.appspot.com/o/Barcode%20Data%20Upload%28II%29%2FAnil_puttu_flour_500g.png?alt=media&token=9cf63197-0925-4360-a31a-4675f4f46ae2", 
    "barcode": "8908001921015", 
    "isFmcg": true, 
    "itemName": "Anil puttu flour 500g", 
    "mrp": 58, 
    "_created_at": "2016-10-02T13:49:03.281Z", 
    "_updated_at": "2017-02-22T08:48:09.548Z" 
} 

{ 
    "_id": "ENPCL8ph1p", 
    "categories": [ 
     { 
     "__type": "Pointer", 
     "className": "Category", 
     "objectId": "B4nZeUHmVK" 
     } 
    ], 
    "isActive": true, 
    "imageUrl": "https://firebasestorage.googleapis.com/v0/b/kirananearby-9eaa8.appspot.com/o/Barcode%20data%20upload%2FYippee_Magic_Masala_Noodles,_70_g.png?alt=media&token=d9e47bd7-f847-4d6f-9460-4be8dbcaae00", 
    "barcode": "8901725181222", 
    "isFmcg": true, 
    "itemName": "Yippee Magic Masala Noodles, 70 G", 
    "mrp": 12, 
    "_created_at": "2016-10-02T13:49:03.284Z", 
    "_updated_at": "2017-02-22T08:48:09.074Z" 
} 

我嘗試:

import pandas as pd 
data= pd.read_json('Data.json') 

getting error ValueError: Expected object or value

import json 
with open('gdb.json') as datafile: 
    data = json.load(datafile) 
retail = pd.DataFrame(data) 

error: json.decoder.JSONDecodeError: Extra data: line 2 column 1 (char 509)

with open('gdb.json') as datafile: 
for line in datafile: 
    data = json.loads(line) 
retail = pd.DataFrame(data) 

error: json.decoder.JSONDecodeError: Extra data: line 1 column 577 (char 576)

如何閱讀本JSON到大熊貓

+0

您是否能夠解決它。 –

+0

暫時我沒有把它轉換成.csv文件。 – adimohankv

+0

尋找這個 - https://stackoverflow.com/questions/27046593/parsing-comma-separated-json-from-a-file –

回答

0

我不認爲這是理所應當的默認的問題(我認爲)。但你有沒有試過這個?添加'r'來指定文件是隻讀的。

import json with open('gdb.json', 'r') as datafile: data = json.load(datafile) retail = pd.DataFrame(data)

+0

試過了,同樣的錯誤 – adimohankv

0

我得到了同樣的錯誤,閱讀功能documentation和玩不同的參數。

我解決它使用下面的一個,

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

你可以嘗試其他的東西像

data= pd.read_json('Data.json', lines=True, orient='records')

data= pd.read_json('Data.json', orient=str)