实施该更改后,我没有收到 Numpy 错误,而是格式错误。所以做了下面的改动
filename = 'test.csv'
division = test.iloc[0][4]
division_tuple = tuple(map(int, str(division).split(",")))
sql = cs.execute("""
INSERT INTO sample_table_name
select c.customer_id,
c.customer_name
from(
t.customer_id
t.customer_name
from customer_table t
where division_id in (%s) --changed format here
group by 1,2) c ;
""",(division_tuple)) #and here
虽然这在技术上会使 where 子句在只有一个值时看起来像“where Division_id in (92,)”
,但这仍然是运行它的正确方法,尽管在 92 之后有尾随逗号。