- import pandas as pd
- strtext='[{"ttery":"min","issue":"20130801-3391","code":"8,4,5,2,9","code1":"297734529","code2":null,"time":1013395466000},\
- {"ttery":"min","issue":"20130801-3390","code":"7,8,2,1,2","code1":"298058212","code2":null,"time":1013395406000},\
- {"ttery":"min","issue":"20130801-3389","code":"5,9,1,2,9","code1":"298329129","code2":null,"time":1013395346000},\
- {"ttery":"min","issue":"20130801-3388","code":"3,8,7,3,3","code1":"298588733","code2":null,"time":1013395286000},\
- {"ttery":"min","issue":"20130801-3387","code":"0,8,5,2,7","code1":"298818527","code2":null,"time":1013395226000}]'
- df=pd.read_json(strtext,orient='records')
- df1=df['code'].str.split(',',expand=True)
- df1.columns=['code.%d'%(i+1) for i in range(5)]
- df2=pd.concat([df,df1],axis=1)
- df2.to_excel('pandas处理json.xlsx',index=False,columns=
- ["ttery","issue","code.1","code.2","code.3","code.4","code.5","code1","code2","time"])
复制代码 |