【问题标题】:explode JSON output to columns将 JSON 输出分解为列
【发布时间】:2022-07-23 02:41:36
【问题描述】:

我有一个带有 JSON 输出的 excel 文件,格式如下:

{"text1":"1","text2":"1","text3":"0"}

我想将其转换为以下表格格式

text1 ---xxx--- text2 ---xxx--- text3

1 ---xxx--- 1 ---xxx--- 0

我尝试过使用 json_normalize(),但响应存储在对象类型中,它不起作用

谢谢!

【问题讨论】:

    标签: python json pandas json-normalize


    【解决方案1】:

    要将 JSON 输出转换为 pandas Dataframe,只需使用 pandas DataFrame() 将其包装如下:

    import pandas as pd
    
    jsonOutput = {"text1":"1","text2":"1","text3":"0"}
    
    pd.DataFrame(jsonOutput)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-06-28
      • 1970-01-01
      • 2018-12-06
      • 2021-01-01
      • 2010-12-31
      • 1970-01-01
      • 2022-12-23
      相关资源
      最近更新 更多