1>儲存為二進位制檔案,pkl格式
import pickle
pickle.dump(data,open(`file_path`,`wb`)) #字尾.pkl可加可不加
若檔案過大
pickle.dump(data,open(`file_path`, `wb`),protocol=4)
讀取該檔案:
data= pickle.load(open(`file_path`,`rb`))
2>儲存為二進位制檔案,npz格式
import numpy as np
np.savez(`file_path/file_name.npz`, data1=X,data2=y)
讀取該檔案:
with np.load(`file_path/file_name.npz`) as data:
X = data[`data1`]
y= data[`data2`]
3>DataFrame檔案儲存為.csv
dataframe_file.to_csv(“file_path/file_name.csv”, index=False)
讀取該檔案:
import pandas as pd
df = pd.read_csv(`file_path/file_name.csv`)