How to save files in python

(*-*)浩
Release: 2019-07-04 13:13:17
Original
16012 people have browsed it

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可加可不加
Copy after login

If the file is too large

pickle.dump(data,open('file_path', 'wb'),protocol=4)
Copy after login

Save as binary file, npz format

import numpy as np
np.savez('file_path/file_name.npz', data1=X,data2=y)
Copy after login

DataFrame file is saved as .csv

dataframe_file.to_csv("file_path/file_name.csv", index=False)
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!