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')
python学习网,免费的在线学习python平台,欢迎关注!