Skip to content

Instantly share code, notes, and snippets.

@mvaz
Created March 9, 2012 13:24
Show Gist options
  • Save mvaz/2006493 to your computer and use it in GitHub Desktop.
Save mvaz/2006493 to your computer and use it in GitHub Desktop.
Example of executing and reading a query into a pandas dataframe
import cx_Oracle
import pandas
connection = cx_Oracle.connect('username/pwd@host:port/dbname')
def read_query(connection, query):
cursor = connection.cursor()
try:
cursor.execute( query )
names = [ x[0] for x in cursor.description]
rows = cursor.fetchall()
return pandas.DataFrame( rows, columns=names)
finally:
if cursor is not None:
cursor.close()
@i-emek
Copy link

i-emek commented May 3, 2021

It works also for jaydebeapi for fetching data from hive using JDBC driver. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment