ValueError: Expected object or value when reading json as pandas dataframe
样本数据:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | { "_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" } |
我试过了:
1 2 | import pandas as pd data= pd.read_json('Data.json') |
getting error ValueError: Expected object or value
也
1 2 3 4 | 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)
1 2 3 4 | 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读成大熊猫
我得到了同样的错误,阅读了功能文档,并使用不同的参数。
我用下面的那个解决了它,
你可以试试其他的东西
你应该确保终端目录与文件目录相同(当我发生这个错误时,因为我使用了vscode,对我来说意味着vscode中的终端目录与我想要的python文件不一样 执行)
我不认为这将是问题,因为它应该是默认(我认为)。 但你试过这个吗? 添加"r"以指定文件是只读的。
import json
with open('gdb.json', 'r') as datafile:
data = json.load(datafile)
retail = pd.DataFrame(data)