将JSON文件转换为具有定义格式的数据帧

2024-06-24 13:06:30 发布

您现在位置:Python中文网/ 问答频道 /正文

JSON文件由嵌入式数组组成,如:

[[[post,post_label], [response,response_label]],[[post,post_label],[response,response_label]],…]

pd.read_json(url)默认将文件读取到数据帧,如下所示:

---------------------------------------------------
|      column01        |        column02          |
---------------------------------------------------
|   [post,post_label]  | [response,response_label]|
---------------------------------------------------
|   [post,post_label]  | [response,response_label]|
---------------------------------------------------

但是,预期的格式应如下所示:

---------------------------------------------------
|      column01        |        column02          |
---------------------------------------------------
|       post           |       post_label         |
---------------------------------------------------
|     response         |       response_label     | 
---------------------------------------------------
|       post           |       post_label         |
---------------------------------------------------
|     response         |       response_label     | 
---------------------------------------------------

请留言,谢谢


Tags: 文件数据jsonurlreadresponse格式数组