creating an sql query using a DataFrame column

by: spiff, 8 years ago

Last edited: 8 years ago

Based on this qs from stackoverflow:
http://stackoverflow.com/questions/29738859/sql-where-in-clause-using-column-in-pandas-dataframe

I tried:

import pandas as pd

df1 = pd.DataFrame()
df1['col1'] = [1,2,3,4,5]
  
str = ','.join([str(x) for x in df1['col1'].unique().tolist()])


However, I see the below error:
TypeError: 'list' object is not callable

I want to query all the unique items in a column into another SQL table and then append those results to my original dataframe

feels like a syntax issue here? or is there another approach altogether pls?

thanks



You must be logged in to post. Please login or register an account.



I solved this by simply using tuple(list) .. the output comes in the exact way you want to make the sql query

-spiff 8 years ago

You must be logged in to post. Please login or register an account.