Home > Article > Backend Development > How to save files in python
This article mainly introduces a summary of the method of saving files in Python. It is very good and has certain reference value. Friends in need can refer to it.
Save as binary file, pkl format (Recommended learning: Python video tutorial)
import pickle pickle.dump(data,open('file_path','wb')) #后缀.pkl可加可不加
If the file is too large
pickle.dump(data,open('file_path', 'wb'),protocol=4)
Save as binary file, npz format
import numpy as np np.savez('file_path/file_name.npz', data1=X,data2=y)
DataFrame file is saved as .csv
dataframe_file.to_csv("file_path/file_name.csv", index=False)
For more Python related technical articles, please visit the Python Tutorial column to learn
The above is the detailed content of How to save files in python. For more information, please follow other related articles on the PHP Chinese website!