I'm having trouble getting a multi-line sql query to format correctly using replacement values (%s). Any help in getting the function to iterate through a list of planName
, and planData
would be helpful!
# importing the libraries
import numpy as np
import pandas as pd
from sqlalchemy import create_engine
#creating the sql engine
engine = create_engine('insert engine creds here')
# creating the plan and plan_data dictionary
dict = {'plan1': 0, 'plan2':, 1}
#creating the function
def plan_usage(planName, planData):
query = pd.read_sql_query(r'''
select *
from blah
where (planName = %s and plan_data = %s)''', engine)
My goal would be to have the code run the query for plan1
, save the results to a dataframe, then run the query for plan2
and save the results to another dataframe.