I made a list of id's each value is is an type int
temp_id = [7922, 7018, 5650, 209, 21928, 2294, 10507, 3623]
type(tempasn)
list
This works:
Temp = pd.read_sql("select count(*) as count\
from "+db+"\
where ids in (7922, 7018, 5650, 209, 21928, 2294, 10507, 3623)\
order by count desc limit 10", conn)
I want to take the variable of the list add it to my query
This causes errors
Temp = pd.read_sql("select count(*) as count\
from "+db+"\
where ids in "+temp_id+"\
order by count desc limit 10", conn)
TypeError: Can't convert 'list' object to str implicitly
I don't understand what I need to change here
Answer
Ended up taking the advise of the comments below and modified my loop which generates the temp_ids:
temp_id = []
for id in df['ID']:
if id and id not in temp_id:
temp_id.append(str(ID))
#Convert to list format
temp_id = ", ".join(temp_id)
2 things made this work :
str(ID) & temp_id = ", ".join(temp_id)
"("+str(temp_id).strip('[]')+")"