I have a pandas dataframe that has a column of IDs. I need to run another sql query whose \'WHERE\' clause is dictated by all of the IDs in the aforementioned column.
str = ','.join([str(x) for x in df1['IDs'].tolist()])
str
'1,2,3,4,5,6'
And, then insert it into the query string -
qry = "Select id, SUM(revenue) AS revenue WHERE id IN (%s) Group by 1" % str
qry
'Select id, SUM(revenue) AS revenue WHERE id IN (1,2,3,4,5,6) Group by 1'