Created
March 11, 2020 03:46
-
-
Save YiLi225/896984b9c0d73a56c76902d18942ac00 to your computer and use it in GitHub Desktop.
This file contains 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 | |
def getSQL(sql_query, | |
place_holder_str, | |
replace_place_holder_with, | |
database_con): | |
''' | |
Args: | |
sql_query: sql query file | |
place_holder_str: string in the original sql query that is to be replaced | |
replace_place_holder_with: real values that should be put in | |
database_con: connection to the database | |
''' | |
sqlFile = open(sql_query, 'r') | |
sqlQuery = sqlFile.read() | |
sqlQuery = sqlQuery.replace(place_holder_str, replace_place_holder_with) | |
df = pd.read_sql_query(sqlQuery, database_con) | |
database_con.close() | |
return df |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment