嗨,字典数据如下所示:
{'Count': 5, '_id': {'ele_id': ['17cd-4a9f-9671-80eda11f9c53'], 'day': '2015-09-22'}, 'name': 'Default Astn'}
{'Count': 2, '_id': {'ele_id': ['17cd-4a9f-9671-80eda11f9c53'], 'day': '2015-09-18'}, 'name': 'Default Astn'}
{'Count': 1, '_id': {'ele_id': ['ccdf-4e0b-a87c-4e7738a0ed33'], 'day': '2015-09-14'}, 'name': 'sharepoint Astn'}
{'Count': 1, '_id': {'ele_id': ['2b9f-436b-a2ff-c4bc4059a9c8'], 'day': '2015-09-14'}, 'name': 'JPL Astn'}
{'Count': 2, '_id': {'ele_id': ['17cd-4a9f-9671-80eda11f9c53'], 'day': '2015-09-14'}, 'name': 'Default Astn'}
要写入CSV,列和数据如下:
^{pr2}$我面临的问题是3行,如果第1列已经相同,只需添加2列和第3列。 我的代码如下
with open('test.csv', 'wb') as f:
fieldnames = ['Date','Name','Count']
writer = csv.DictWriter(f, fieldnames=fieldnames)
writer.writeheader()
for line in data:
writer.writerow({'Date' : line['_id']['day'],'Name' : line['name'], 'Count':line['Count']})
试试这个。。。。。还没有测试,但我觉得逻辑还是一样的。。。。。。在
相关问题 更多 >
编程相关推荐