gpt4 book ai didi

python - 将 JSON 文件转换为具有定义格式的 Dataframe

转载 作者:行者123 更新时间:2023-12-01 00:56:48 26 4
gpt4 key购买 nike

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

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

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

---------------------------------------------------
| 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 |
---------------------------------------------------

请留言,谢谢。

最佳答案

你可以做另一件事:

print(pd.DataFrame(df.values.flatten().tolist(),columns=df.columns))

输出将根据需要进行。

关于python - 将 JSON 文件转换为具有定义格式的 Dataframe,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56178779/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com