Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 将JSON读取到dataframe-ValueError:将DICT与非序列混合可能导致排序不明确_Python_Json_Pandas - Fatal编程技术网

Python 将JSON读取到dataframe-ValueError:将DICT与非序列混合可能导致排序不明确

Python 将JSON读取到dataframe-ValueError:将DICT与非序列混合可能导致排序不明确,python,json,pandas,Python,Json,Pandas,我试图将下面的JSON结构读入pandas dataframe,但它抛出了错误消息: ValueError:将DICT与非系列混用可能导致不明确 订购 Json数据: { "status": { "statuscode": 200, "statusmessage": "Everything OK" }, "result": [{ "id": 22, "club_id": 16182 }, {

我试图将下面的JSON结构读入pandas dataframe,但它抛出了错误消息:

ValueError:将DICT与非系列混用可能导致不明确 订购

Json数据:

{
    "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
    }]
}
我怎样才能做到这一点?我试过下面的脚本

j_df = pd.read_json('json_file.json')
j_df

with open(j_file) as jsonfile:
    data = json.load(jsonfile)

如果您只需要数据帧中的结果部分,那么下面的代码可以帮助您

import json
import pandas as pd
data = json.load(open('json_file.json'))

df = pd.DataFrame(data["result"])
您可以使用:


如果您只需要数据框中的结果部分,以下代码可帮助您:

import json
import pandas as pd
data = json.load(open('json_file.json'))

df = pd.DataFrame(data["result"])
据我所知,发生ValueError是因为数据类型到处都是,一些字符串、一些列表、多个{}等等。这个错误可以通过规范化数据来解决。为此,以下是代码:

import json

with open('json_file.json') as project_file:    
    data = json.load(project_file)  

df = pd.json_normalize(data)
import json

with open('json_file.json') as project_file:    
    data = json.load(project_file)  

df = pd.json_normalize(data)