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 |
---------------------------------------------------
请提供一些信息,谢谢。
答案 0 :(得分:2)
您可以再做一个:
print(pd.DataFrame(df.values.flatten().tolist(),columns=df.columns))
将根据需要输出。