简体   繁体   中英

How do I view a specific table from a SQlite3 databse using python?

I use the below code to read a table called 'movies' from the database saved as 'ga2.db'

conn = sqlite3.connect('ga2.db')
cur = conn.cursor()
pd.read_sql_table('movies', con=conn)

But I get this error "NotImplementedError: read_sql_table only supported for SQLAlchemy connectable." and I can't seem to find an example for how I can inspect a database table so that I can inspect its contents.

Use pd.read_sql_query instead:

conn = sqlite3.connect('ga2.db')
qry = '''SELECT * FROM movies'''
df = pd.read_sql_query(qry, con=conn)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM