我试图在下面的JSON结构中读入pandas dataframe,但它抛出了错误消息:
ValueError:将dicts与非Series混合可能会导致模糊排序.
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
}]
}
Run Code Online (Sandbox Code Playgroud)
我怎么做到这一点?我试过下面的脚本......
j_df = pd.read_json('json_file.json')
j_df
with open(j_file) as jsonfile:
data = json.load(jsonfile)
Run Code Online (Sandbox Code Playgroud) 看来我可以同时使用pandas和/或json来读取json文件,即
import pandas as pd
pd_example = pd.read_json('some_json_file.json')
Run Code Online (Sandbox Code Playgroud)
或者,等效地,
import json
json_example = json.load(open('some_json_file.json'))
Run Code Online (Sandbox Code Playgroud)
所以我的问题是,有什么区别,我应该使用哪一个?是否建议一种方法优于另一种方法?在某些情况下,一种方法比另一种更好吗?谢谢。