Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save alittlesliceoftom/83b027aefbea7ea0c822067de232502c to your computer and use it in GitHub Desktop.
Save alittlesliceoftom/83b027aefbea7ea0c822067de232502c to your computer and use it in GitHub Desktop.
import pandas as pd
import sqlalchemy as sa
import configparser
from os import path
configfile = 'config.ini'
config = configparser.ConfigParser()
config.read(path.dirname(__file__) + '/' + configfile)
server = config['Database']['server']
database = config['Database']['Database']
driver = "SQL Server"
connection_string = "mssql://{server}/{database}?driver={driver}?trusted_connection=True"
"mssql://{server}/{database}?driver={driver}?trusted_connection=True"
engine = sa.create_engine(connection_string.format(server=server, database=database, driver=driver))
columns = ['GasFlowDate','LDZ','ALP','DAF','SNCWV','SND'
,'WSENS'
,'EWCF'
,'WAALP'
,'WAALP_adjusted']
df = pd.read_sql_table(table_name= 'vwWAALP', schema= 'gas', con = engine, columns =columns)
sql_file = open(r'example.sql')
sql = sql_file.read()
df2 = pd.read_sql(sql = sql, con = engine )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment