Created
April 14, 2017 08:45
-
-
Save JaimeEnergy/4dc8e4151139a9d601efb3e46a1e80d6 to your computer and use it in GitHub Desktop.
Connect to SQL Server, Postgres, and SQLite3 in Python
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 pypyodbc | |
import pandas as pd | |
CONNECTION_STRING = """ | |
Driver={{{DRIVER}}}; | |
Server={SERVER}; | |
Database={DATABASE}; | |
""".format(**locals()) | |
df = pd.read_sql(con=pypyodbc.connect(CONNECTION_STRING), sql=sql) | |
# optional http://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_sql.html | |
# index_col: str or list of str -> to set index | |
# columns: str or list of str -> to restrict columns selected | |
# chunksize: int -> stream a large table |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment