pandas from

编程入门 行业动态 更新时间:2024-10-27 18:18:42
本文介绍了 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

本文发布于:2023-11-09 09:09:24,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1571990.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:pandas

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!