I am new to stackoverflow and python so please forgive me if this question lacks detail
I want to import data from a csv file to a table in Postgres. However, I'm not sure how to check for null values. I would like to import certain values as ints (these values for some reason have a .0 trailing them ie 10.0 when I want 10) . Some of the cells for on_hand and on_order are null
though - how would I go about checking to see if these cells are null
and if they are null
, to simply do a row[2].strip
and row[3].strip
?
for row in reader:
arg = {
'name': row[0].strip(),
'description': row[1].strip(),
'on_hand': int(float(row[2].strip())),
'on_order': int(float(row[3].strip()))
}
cur.execute(
"""INSERT INTO
"Inventory"("Name","Description","On hand","On order")
select %(name)s,
%(description)s,
%(on_hand)s,
%(on_order)s,
WHERE NOT EXISTS (
SELECT * FROM "Inventory" WHERE "Name"=%(name)s
);""", arg)
thanks!