python npz转csv
import numpy as np import pandas as pd file = np.load('x_train.npz',allow_pickle=True) #查看其中的npy文件名,其实npz文件就是由多个npy文件压缩而成的,winrar即可解压缩 for ii in file: print(ii) ##indices ##indptr ##format ##shape ##data ## file.files ##['indices', 'indptr', 'format', 'shape', 'data'] #解压缩后: npfile=np.load("C:\python37\x_train\data.npy") npfile=np.load("C:\\python37\\x_train\\data.npy") npp=pd.DataFrame(data=npfile) npp.to_csv("data.csv") columns = file['indices'] values = file['data'] np.savetxt("mm.csv",file,delimiter=',',fmt='%f') ##for key,value in file.items(): ## print(key,value) #np.savetxt("nn"+key+".csv",values) ## ##from pandas import DataFrame ###pd.DataFrame(values,columns=columns) ##a=DataFrame(values,columns=columns) ###a.to_excel('国民经济核算季度数据.xlsx',index=None) ##a.to_csv('test.csv',index=None)