Answers / Get data into your AI
How do I upload a pandas DataFrame so Claude can query it?
Recipe verified on
Ran on a private test instance
Short answer
Write it with the cdb client: s.write_table("name", df). It becomes a table Claude can query over MCP straight away, and replace=True swaps in a new version later while keeping the old one.
Steps
- Connect your assistant to your instance (this writes, so it needs your own instance with a ReadWrite key
from the accounts portal; the public demo is read-only). In Claude Code:
claude mcp add --transport http mcpdata https://[you].mcpdata.org/mcp --header "Authorization: Bearer $CDB_API_KEY"
Replace
[you]with your instance's name. Other apps: Connect your AI. - Install the client. Then sign this computer in once (
cdb-localdata login --to https://[you].mcpdata.org), or setCDB_API_KEY.pip install https://[you].mcpdata.org/help/download/cdb-0.3.4-py3-none-any.whl
- Write the DataFrame.
import cdb import pandas as pd df = pd.DataFrame({"region": ["EMEA", "Americas", "APAC", "EMEA"], "product": ["A", "B", "A", "C"], "sales": [1200.0, 950.5, 430.25, 610.0]}) s = cdb.Session("https://[you].mcpdata.org") s.write_table("py.sales", df, replace=True) print(s.execute_sql("SELECT COUNT(*) AS n FROM py.sales").to_dataframe()) - Ask your question. Give your AI this prompt:
Using mcpdata, total sales by region from py.sales.
What your AI does: the tool call it makes for this prompt, and what came back
query(table_name="py.sales", group_by=["region"], agg=[{"func": "sum", "column": "sales", "alias": "sales"}], sort=[{"column": "sales", "desc": true}]) → 3 rows
| region | sales |
|---|---|
| EMEA | 1,810.00 |
| Americas | 950.50 |
| APAC | 430.25 |
The assistant needs mcpdata connected (step 1) to run the query.
Why this works
The DataFrame stays a proper table with its column types, rather than text in a prompt. Python and Claude then read the same data, so a number in your notebook and in Claude's answer come from the same rows.