I have this dummy code below. Pretty much what I am trying to do is create a table with all the customers and their ID's in a division or division(s) that is specific in an excel sheet. In the excel cell, there can be either one division listed or several. The code below works if there are multiple divisions, however if there is only one, then the code does not work as I am creating a tuple and the where clause essentially becomes something like where division_id in (92,) which runs a SQL error. How can I write this code so that it can both handle multiple divisions and just single divisions.
Code:
filename = 'test.csv'
division = test.iloc[0][4]
division_tuple = tuple(map(int, 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 {}
group by 1,2) c ;
""".format(division_tuple))
I get the following error if the excel sheet only has one listed division:
Error from Code:
Traceback (most recent call last): division_tuple = tuple(map(int, division.split(","))) AttributeError: 'numpy.int64' object has no attribute 'split'
I have also attatched an image of what the cell would look like with one division, if there are multiple, it would be the same but like "92,100,203" etc.
Data:
