Home>Article>Backend Development> How to save files in python

How to save files in python

(*-*)浩
(*-*)浩 Original
2019-07-04 13:13:17 15951browse

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.

How to save files in python

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 thePython Tutorialcolumn 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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn