json导出表格问题

1.大神已经解决几个json合并问题
首选感谢timeswind大神
https://segmentfault.com/q/1010000004733...

2.我想在这个基础上 导出表格 代码如下

import json
import pandas as pd
import numpy as np

jsonOne = {
    "data": [
        {
            "id": "123456",
            "create_time": "2016-03-28 11:41:00",
            "phone": "138888****",
            "name": "aaa"
        },
        {
            "id": "456789",
            "create_time": "2016-03-30 11:41:00",
            "phone": "138888****",
            "name": "bbb"
        }
    ]
}

jsonTwo = {
    "data": [
        {
            "id": "123456",
            "driver": "2016-03-28",
            "work": "work1",
            "type": "A"
        },
        {
            "id": "456789",
            "driver": "2016-03-28",
            "work": "work2",
            "type": "B"
        }
    ]
}

newJson = {
    "data": []
}

for index,item in enumerate(jsonOne['data']):
    newObj = {
        "id": item["id"],
        "create_time": item["create_time"],
        "phone": item["phone"],
        "name": item["name"],
        "driver": jsonTwo["data"][index]["driver"],
        "work": jsonTwo["data"][index]["work"],
        "type": jsonTwo["data"][index]["type"]

    };
    newJson["data"].append(newObj)


print(newJson["data"]);

test = pd.DataFrame(newJson)

test.to_csv('hello.csv')

print '------------OK-------------'

然后表格输出就是这样
图片描述

阅读 4.2k
1 个回答

我猜你是没加["data"],所以你那个pd解析不了data


test = pd.DataFrame(newJson["data"])
test.to_csv('hello.csv')
print(test)

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题
宣传栏