本文介绍了 pandas from_json方法的用法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个如下所示的JSON文件,
I have a JSON file like below,
{ "A":1, "B":2, "C": [ {"x":1,"y":2,"z":3}, {"x":2,"y":7,"z":77} ] }pandas.from_json返回带有列A,B和C的数据帧.但是,实际上,我正在寻找带有x,y和z的列.有办法吗?
pandas.from_json returns me data frame with column A,B and C. But, actually I am looking for columns with x,y and z. Is there a way to get it?
推荐答案您可以使用 json_normalize :
You can use json_normalize:
json = { "A":1, "B":2, "C": [{"x":1,"y":2,"z":3 }, {"x":2,"y":7,"z":77}] } from pandas.io.json import json_normalize df = json_normalize(json, 'C') print (df) x y z 0 1 2 3 1 2 7 77如果需要所有列:
df = json_normalize(json, 'C', ['A','B']) print (df) x y z B A 0 1 2 3 2 1 1 2 7 77 2 1更多推荐
pandas from
发布评论