Если имя столбца bill_id
и требуется цикл для каждого уникального клиента:
for cust in data['bill_id'].unique():
customer_details = f"""select cust_name, bill_id from customers where bill_id in ({cust})"""
print (customer_details)
select cust_name, bill_id from customers where bill_id in (1001)
select cust_name, bill_id from customers where bill_id in (1002)
select cust_name, bill_id from customers where bill_id in (1003)
select cust_name, bill_id from customers where bill_id in (1006)
select cust_name, bill_id from customers where bill_id in (1007)
data = pd.read_sql(customer_details, con=con1)
Или, если нужны все уникальные клиенты:
all_data = ', '.join(data['bill_id'].unique().astype(str))
customer_details = f"""select cust_name, bill_id from customers where bill_id in ({all_data})"""
print (customer_details)
select cust_name, bill_id from customers where bill_id in (1001, 1002, 1003, 1006, 1007)
data = pd.read_sql(customer_details, con=con1)