I'm trying to display the contents of a (local) sqlite table in Excel. I want to use "Python in Excel" for various reasons. This is the code I have written in cell A1 using the PY() formula:

import pandas as pd import sqlite3 my_db = f'C:\\Users\\benpr\\mu_code\\nbssh.db' conn = sqlite3.connect(my_db) my_query = f'select * from results' df = pd.read_sql_query(my_query, conn)

But I am getting the following when I try and validate:

Error: Python

DatabaseError: Execution failed on sql 'select * from results': no such table: results

The table definitely exists and if I run the identical code in a Python script it queries and displays the dataframe without in any issue. From what I understand there are no extra steps I need to take when using Python in Excel so I'm at a loss to work out what I have not done right?

Tantalan's user avatar

New contributor

Tantalan is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

The problem is not SQL, the problem is where your code is running.

You use =PY() in Excel, therefore the Python code runs in a "cloud" environment, not your local computer. So, your code isn't running where you think it is.

The path "C:\Users\benpr\mu_code\nbssh.db" doesn't exist where your code is running.

SQLite doesn't raise an error if the database does not exist. Instead, it creates a new database. That's why you get "no such table: results" on each cycle of process.

the busybee's user avatar

the busybee

13.4k3 gold badges16 silver badges36 bronze badges

Varun Dubey's user avatar

1 Comment

Ok now this makes perfect sense, thanks so much will have to rethink my approach!

2026-03-21T06:53:43.31Z+00:00

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.