Search code examples
pythonpandasdatabasesqliteconnection

Reading SQL-table by pandas raises NotImplementedError


Could somebody help with pandas. I can't read sqlite3 table.

This is my code:

import pandas as pd
import sqlite3 as sq

with sq.connect("master.db") as con:
    table = "personal"
    df = pd.read_sql_table(table, con)

Database file and code are in same directory. Python raises NotImplementedError.


Solution

  • If you want to read the content of your table you can simply use:

    import pandas as pd
    import sqlite3 as sq
    
    with sq.connect("master.db") as con:
       params = ["personal"]    
       df = pd.read_sql_query("SELECT * FROM ?", con, params = params)
    

    As stated in the comments, the usage of params in the query is recommended to block sql-injections