這篇文章主要講解了python如何實(shí)現(xiàn)把json數(shù)據(jù)轉(zhuǎn)換成Excel表格,內(nèi)容清晰明了,對(duì)此有興趣的小伙伴可以學(xué)習(xí)一下,相信大家閱讀完之后會(huì)有幫助。
成都創(chuàng)新互聯(lián)公司服務(wù)項(xiàng)目包括甘州網(wǎng)站建設(shè)、甘州網(wǎng)站制作、甘州網(wǎng)頁制作以及甘州網(wǎng)絡(luò)營銷策劃等。多年來,我們專注于互聯(lián)網(wǎng)行業(yè),利用自身積累的技術(shù)優(yōu)勢、行業(yè)經(jīng)驗(yàn)、深度合作伙伴關(guān)系等,向廣大中小型企業(yè)、政府機(jī)構(gòu)等提供互聯(lián)網(wǎng)行業(yè)的解決方案,甘州網(wǎng)站推廣取得了明顯的社會(huì)效益與經(jīng)濟(jì)效益。目前,我們服務(wù)的客戶以成都為中心已經(jīng)輻射到甘州省份的部分城市,未來相信會(huì)繼續(xù)擴(kuò)大服務(wù)區(qū)域并繼續(xù)獲得客戶的支持與信任!json數(shù)據(jù):
[{"authenticate":-99,"last_ip":"156.2.98.429","last_time":"2020/05/23 01:41:36","member_id":5067002,"mg_id":1,"name":"yuanfang","status":0,"username":"L7898"},{"authenticate":-99,"last_ip":"156.2.98.421","last_time":"2020/05/20 14:16:02","member_id":1012304,"mg_id":1,"name":"管理員","status":0,"username":"aaaap"},{"authenticate":-99,"last_ip":"134.212.156.178","last_time":"2020/04/20 14:16:03","member_id":1012305,"mg_id":1,"name":"lily","status":0,"username":"aaaaa8"}]
將json數(shù)據(jù)轉(zhuǎn)化為Excel表格
首先在cmd里安裝tablib模塊,tablib 模塊可以完美實(shí)現(xiàn),json 轉(zhuǎn) excel,安裝方法:pip instal tablib
#!/usr/bin/python3 #防止出現(xiàn)中文亂碼 # -*- coding:utf-8 -*- import json import tablib # json.text文件的格式: [{"a":1},{"a":2},{"a":3},{"a":4},{"a":5}] # 獲取json數(shù)據(jù) with open('F:\\閱維科技2020.4\\python測試數(shù)據(jù)\\json1.txt', 'r',encoding='utf-8',errors='ignore') as f: rows = json.load(f) # 將json中的key作為header, 也可以自定義header(列名) header=tuple([ i for i in rows[0].keys()]) data = [] # 循環(huán)里面的字典,將value作為數(shù)據(jù)寫入進(jìn)去 for row in rows: body = [] for v in row.values(): body.append(v) data.append(tuple(body)) #將含標(biāo)題和內(nèi)容的數(shù)據(jù)放到data里 data = tablib.Dataset(*data,headers=header) #寫到桌面 open('C:\\Users\\91911\\Desktop\\data.xls', 'wb').write(data.xls)