為了方便進行深度學習的程序調用與實現,需要將excel的數據文件轉換為二進制文件。好處就是接口統一,讀寫速度快,節約空間。
一、調用庫
使用xlrd讀入execel表格,經過處理后轉換為對應的dataframe結構,再使用pickle庫保存。
?
二、實例
import struct
import os
import pickle, glob#寫入bin文件
#假設已生成datafarme。
binname = './test.bin'
binfile = open(binname , 'rb+') #打開bin文件
pickle.dump(datafarme,binfile) #寫入datafarme#讀取bin文件
binname = './test2.bin'
binfile2 = open(binname,'rb')
readdata = pickle.load(binfile2 )
print(readdata.shape)
三、讀寫文件參數
?open(binname , 'rb+') ,后面一個參數的選擇如下圖所示
參考文獻:
https://blog.csdn.net/qq_32166627/article/details/68946809
https://blog.csdn.net/and_then111/article/details/86744938