【问题标题】:Parsing Panda to_dict解析熊猫 to_dict
【发布时间】:2019-11-29 22:20:40
【问题描述】:

我有数据正在通过 API 获取,但数据是 HTML 格式,所以我使用 panda 将 HTML 转换为 to_dict 但是在 Django 中获取数据时,它添加了字符串环绕,我不是能够使用for循环来解析数据。如何删除字符串以便我可以获取数据。

数据:

output = fetchdata(datacenter)

    ## Dict format to fetch
    context = {
        'datacenter': datacenter,
        'output': output
    }
Here is the below OUTPUT:

{'datacenter': 'DC1', 'output': b"[{'Device': 'device01', 'Port': 'Ge0/0/5', 'Provider': 'L3', 'ID': 3324114459135, 'Remote': 'ISP Circuit', 'Destination Port': 'ISP Port'}, {'Device': 'device02', 'Port': 'Ge0/0/5', 'Provider': 'L3', 'ID': 334555114459135, 'Remote': 'ISP Circuit', 'Destination Port': 'ISP Port'}]\n"}

我想从输出中获取数据并以表格格式显示

【问题讨论】:

    标签: python pandas list dictionary


    【解决方案1】:

    输出应该是json对象,所以:

    import json
    
    json.loads(output)
    

    它必须有效。

    【讨论】:

    • 我尝试了第一件事,但没有成功。通过 Django dict 运行 python 脚本的问题,但它将整个数据转换为字符串。不知道如何从字典中获取数据
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-12-29
    • 2020-10-19
    • 1970-01-01
    • 2018-07-31
    • 2021-08-29
    • 2014-08-21
    • 2016-06-04
    相关资源
    最近更新 更多