Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Read JSON to pandas dataframe - ValueError: Mixing dicts with non-Series may lead to ambiguous ordering

I am trying to read in the JSON structure below into pandas dataframe, but it throws out the error message:

ValueError: Mixing dicts with non-Series may lead to ambiguous ordering.

Json data:

{     "status": {         "statuscode": 200,         "statusmessage": "Everything OK"     },      "result": [{         "id": 22,         "club_id": 16182     }, {         "id": 23,         "club_id": 16182     }, {         "id": 24,         "club_id": 16182     }, {         "id": 25,         "club_id": 16182     }, {         "id": 26,         "club_id": 16182     }, {         "id": 27,         "club_id": 16182     }] } 

How do I get this right? I have tried the script below...

j_df = pd.read_json('json_file.json') j_df  with open(j_file) as jsonfile:     data = json.load(jsonfile) 
like image 452
userPyGeo Avatar asked Mar 27 '18 06:03

userPyGeo


1 Answers

If you just need the result part in a dataframe, then here is the code to help you.

import json import pandas as pd data = json.load(open('json_file.json'))  df = pd.DataFrame(data["result"]) 
like image 177
Rao Sahab Avatar answered Sep 26 '22 20:09

Rao Sahab