productner
productner copied to clipboard
IndexError while running 'python supplement.py products.normalized.trimmed.csv'
Hello etano
I was trying to execute the commands as you have provided. But after trimming and running the following all scripts give the index error.
productner-master\data>python supplement.py products.normalized.trimmed.csv
Traceback (most recent call last):
File "supplement.py", line 15, in
Kindly let me know if any other details are needed.
I'm facing the same problem. Any solution to this?
Hey guys-- @UTS-ExplainableRecommendation @Nidhibar
Try this fix, worked for me.
`import sys, csv, io
in_file = sys.argv[1] out_file = '.'.join(in_file.split('.')[:-1] + ['supplemented'] + ['csv'])
with io.open(in_file, 'r', encoding='utf-8') as f: reader = csv.reader(f) writer = csv.writer(io.open(out_file,"w", encoding='utf-8')) count, supplemented = 0, 0 for row in reader: count += 1 if not (count % 10000): print (supplemented, '/', count, 'rows supplemented') try: title = row[0] except: title = '' continue try: brand = row[1] except: brand = '' continue try: description = row[2] except: description = '' continue
if not (brand in title):
supplemented += 1
title = brand + ' ' + title
description = title + ' ' + description
try:
title = row[0]
except:
title = ''
continue
try:
brand = row[1]
except:
brand = ''
continue
try:
description = row[2]
except:
description = ''
continue
writer.writerow(row)
print (supplemented, '/', count, 'rows supplemented')`