import pandas as pd
import cx_Oracle
dsn = cx_Oracle.makedsn(host='host', port='port', service_name='service_name')
con = cx_Oracle.connect(user='user_name', password='my_password', dsn=dsn)
df = pd.read_sql(f"""
select
customer_name,
sku,
sum(units_sold) units_sold
from
oracle_schema.oracle_table
group by
customer_name,
sku""", con=con)
The cx_Oracle module in Python enables access to an Oracle Database.
In this example I demonstrate how to integrate the cx_Oracle module with pandas. Specifically, the cx_Oracle module is used to create the dsn and database connection. This information is then passed into the pandas read_sql method to retrieve the data.