How to save a pandas DataFrame

To save a DataFrame in pandas, call one of its to_* methods. For most work, use Parquet:

df.to_parquet("sales.parquet")
df = pd.read_parquet("sales.parquet")

Which one to choose depends on what has to survive the trip, and who reads the file next.

The formats compared

FormatSave withKeeps typesGood for
Parquetdf.to_parquet("sales.parquet")MostYour default: compact and fast, and read by most data tools
CSVdf.to_csv("sales.csv", index=False)NoAnything that needs plain text
Exceldf.to_excel("sales.xlsx", index=False)PartlyHanding a file to someone who opens it in a spreadsheet
Pickledf.to_pickle("sales.pkl")YesA short-lived cache in your own code
SQLdf.to_sql("sales", engine)Mapped to the database’s typesData that belongs in a database you already have

Parquet needs an engine installed: pyarrow, or fastparquet. Excel needs openpyxl to write and read .xlsx. to_sql takes a SQLAlchemy engine, or a sqlite3 connection.

Parquet keeps the usual column types: integers, floats, booleans, text, dates and timestamps with their time zone, categories, and pandas’ nullable types. It isn’t a perfect copy of everything a DataFrame can hold: a column of mixed Python objects may not write at all, and some pandas-only details don’t survive every tool that reads the file.

The mistakes to look out for

CSV loses your types. Dates come back as text unless you pass parse_dates, IDs like 007 come back as the number 7, and a whole-number column with a missing value comes back as floats. If you must use CSV, say what you expect when you read it:

df = pd.read_csv(
"sales.csv",
dtype={"id": "string", "quantity": "Int64"},
parse_dates=["sold_at"],
)

"string" keeps leading zeros, and "Int64" (capital I) is pandas’ nullable integer: whole numbers, with missing values as <NA> instead of turning the column into floats.

to_csv writes the index by default. Without index=False, reading the file back gives you an extra Unnamed: 0 column.

Only unpickle what you trust. Reading a pickle can run code hidden in the file, so never open one from someone else. Pickles are also Python-only, and can fail to load in another version of pandas, so don’t use them to keep data for long or to hand it to another tool.

Large files. Parquet is already compressed. For CSV, a name ending in .csv.gz is enough to make pandas compress it:

df.to_csv("sales.csv.gz", index=False)

When a file isn’t enough

A Parquet file is enough for most work, also when you share it or keep a few versions of it. A hosted table is worth it when the DataFrame has to be somewhere other code and people can reach:

rho keeps a DataFrame as a hosted table, named by a path. A file on disk is yours to name, copy and keep; a rho table is one place every script and agent reads from, where every write is a version.

Save a DataFrame to rho

Install the SDK, and make an API token in the rho app (API tokens, in the sidebar):

pip install "rho-store[pandas]"
export RHO_API_KEY=rho_sk_...

Save a DataFrame as a table:

import pandas as pd
import rho
october = pd.DataFrame(
{"country": ["SE", "DK", "DE"], "orders": [412, 105, 329], "revenue": [48200.0, 13650.0, 30100.0]}
)
rho.put(october, "reports/sales-by-country", message="October") # version 1

In another script, or another session:

df = rho.get("reports/sales-by-country") # the latest version, as a DataFrame

Next month, write the new figures:

november = october.assign(orders=[430, 98, 341], revenue=[50100.0, 12800.0, 31900.0])
rho.put(november, "reports/sales-by-country", message="November") # version 2

put replaces the table’s rows by default, and that’s safe: the replace is a new version, and the old one stays. Pass mode="append" to add rows, mode="upsert", key="country" to update rows by a key and add the rest, or mode="create" to refuse a table that already exists.

rho makes a version only when you write. It doesn’t watch the DataFrame in memory: change df in pandas, and nothing in rho changes until you put it again.

Read an earlier version

Versions never change, so last month’s data is still there as it was:

october_again = rho.get("reports/sales-by-country", version=1)
rho.history("reports/sales-by-country") # every version: when, by whom, and its message
rho.restore("reports/sales-by-country", version=1) # version 3, with October's rows

A restore is a new version too, so the November data isn’t lost either.

The same table in your AI agent

Once the table is in rho, an AI agent connected to rho (see the Quickstart) can work with it in Claude, ChatGPT, Cursor or any MCP client, with no file to attach. After the November put:

You: Open reports/sales-by-country in rho. Calculate revenue per order by country and identify the highest-performing country.

The agent reads the table’s columns and types, then queries it in SQL, on rho’s side:

SELECT country, round(revenue / orders, 2) AS revenue_per_order
FROM "reports/sales-by-country"
ORDER BY revenue_per_order DESC
countryrevenue_per_order
DK130.61
SE116.51
DE93.55

So: Denmark, at 130.61 per order. The rows don’t pass through the chat; only the answer does. It works the other way too: an agent saves its research as research/competitors, and rho.get("research/competitors") gives it to you as a DataFrame. More on that: A database for your AI agent.

What rho keeps of a DataFrame

Data goes to rho and back as Parquet, so the usual types come back as they went: integers stay integers (a nullable one comes back as Int64), floats, booleans, text, dates, timestamps to the nanosecond, and decimals with their scale. A few things are kept differently:

The Python SDK guide has the rest: Polars and Arrow, SQL queries, async, and making a table public.