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-------------'
然后表格输出就是这样
我猜你是没加["data"],所以你那个pd解析不了data