O'Reilly logo

Hands-On Data Analysis with NumPy and pandas by Curtis Miller

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Saving DataFrames

Suppose we have a DataFrame; call it df. We can easily save the DataFrame's data. We can pickle the DataFrame (which saves it in a format commonly used in Python) with the to_pickle method, passing the filename as the first parameter.

We can save a CSV file with to_csv, a JSON file with to_json, or an HTML table with to_html. Many other formats are available; for example, we can save data in Excel spreadsheets, Stata, DAT files, HDF5 format, and SQL commands to insert it into a database, even copied to your clipboard.

We may discuss other methods along with how to load data in different formats later.

In this example, I save the data in the DataFrame to a CSV file:

Hopefully, by now, you are more familiar with what series ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required