Last active
November 12, 2019 17:24
-
-
Save Vaibhavs10/4ed0db158a7651b5dc610a54dde6fe8d to your computer and use it in GitHub Desktop.
Script to connect with Oracle and create a pandas dataframe
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import pandas as pd | |
| from sqlalchemy import create_engine | |
| import cx_Oracle | |
| oracle_connection_string = ( | |
| 'oracle+cx_oracle://{username}:{password}@' + | |
| cx_Oracle.makedsn('{hostname}', '{port}', service_name='{service_name}') | |
| ) | |
| engine = create_engine( | |
| oracle_connection_string.format( | |
| username='CALCULATING_CARL', | |
| password='12345', | |
| hostname='all.thedata.com', | |
| port='1521', | |
| service_name='every.piece.ofdata', | |
| ) | |
| ) | |
| data = pd.read_sql("SELECT * FROM …", engine) | |
| ## Second Approach | |
| import pandas as pd | |
| from sqlalchemy import create_engine | |
| oracle_connection_string = 'oracle+cx_oracle://{username}:{password}@{hostname}:{port}/{database}' | |
| engine = create_engine( | |
| oracle_connection_string.format( | |
| username='CALCULATING_CARL', | |
| password='12345', | |
| hostname='all.thedata.com', | |
| port='1521', | |
| database='everything', | |
| ) | |
| ) | |
| data = pd.read_sql("SELECT * FROM …", engine) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment