I'm working with an Oracle database. I can do this much:
import pandas as pdimport pandas.io.sql as psqlimport cx_Oracle as odbconn = odb.connect(_user +'/'+ _pass +'@'+ _dbenv)sqlStr = "SELECT * FROM customers"df = psql.frame_query(sqlStr, conn)
But I don't know how to handle bind variables, like so:
sqlStr = """SELECT * FROM customers WHERE id BETWEEN :v1 AND :v2"""
I've tried these variations:
params = (1234, 5678)params2 = {"v1":1234, "v2":5678}df = psql.frame_query((sqlStr,params), conn)df = psql.frame_query((sqlStr,params2), conn)df = psql.frame_query(sqlStr,params, conn)df = psql.frame_query(sqlStr,params2, conn)
The following works:
curs = conn.cursor()curs.execute(sqlStr, params)df = pd.DataFrame(curs.fetchall())df.columns = [rec[0] for rec in curs.description]
but this solution is just...inellegant. If I can, I'd like to do this without creating the cursor object. Is there a way to do the whole thing using just pandas?