I have a csv file with string items in each file. (although some are integer inputs). I wish to subtract row[3] from row[5], but can't quite figure out the syntax to do so. Can anyone help?
print("PRINT RECORD" + '\t'+ row[0]+ '\t' + int(row[5])-int(row[3]))
The error message is:
ValueError: invalid literal for int() with base 10: 'Target Stock'
I've tried a number of different things which don't work
UPDATE
ID NO. Description Price Current Stock Re Order Target Stock
12345670 x 500 2 3 5
12121212 y 900 1 3 5
I need the statement to subtract (in this example): 5-2 and then 5-1
UPDATE:
I tried
while row[5] and row[3] != str:
print("LOW STOCK" + '\t'+ row[0]+ '\t' + (int(row[5])-int(row[3])))
Still, the same error.
UPDATE I've added the header search...but the following error
l=str(row[4])
for row in reader:
if(row[3])< (row[4]):
has_header = csv.Sniffer().has_header(inf.read(1024))
if has_header:
next(incsv) # skip header row
lowstock="true"
targetstock_r= int((row[5]))
currentstock_r=int((row[3]))
reorderstock_r=int((row[4]))
writer.writerow(("LOWSTOCK", row[0],(targetstock)-(row[3])))
ERROR MESSAGE:
NameError: name 'inf' is not defined