Sep-05-2019, 01:01 PM
A bit new and doing self teaching for python, but I am trying to figure out how best to use an existing dataframe to pass a column value into a where clause for a sql query to return results. However, it is not working as I am intending as it repeats the header from the custom function I am wrote to perform this. I would add that my goal is to solve how I can pass the dataframes column whether 10 or 10,000 records to get a value back from the database so I believe tuples will not work here.
Here is my function:
Here is my function:
def overrides(id): sql = f"select name from sales..rep where id in({id})" mydf = pd.read_sql(sql, cnxn) return mydfHere is how I apply it:
dfnew = dfrep['ID'].apply(overrides)Here is the results
Output: name
0 BOB
name
0 JIM
name
0 KEN
name
0 GREG
name
0 STEVE