Skip to content
Advertisement

Converting list to comma separated integers to be substituted in IN clause of Pandas dataframe query

I have a list of integers that contains EMPI_ID

JavaScript

I have a variable that defines the SQL query

JavaScript

Columns for the dataframe:

JavaScript

When I try to convert them to comma separated integer values, the sql_string hold Str values and is failing to fetch the data from database.

JavaScript

Please advise how i can change the query to substitute the IN clause of SQL with list of integers. from_records does not have param as parameter to pass the joined sql string.

Advertisement

Answer

list comprehension is you friend

JavaScript

output:

JavaScript

join only works with str, so you have to convert the elements in the list, thats where you can use list comprehension. With the join, you can enter them into the query.

EDIT: if you want the numbers quoted, try this

JavaScript

giving this output:

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement