import csv

file1reader = csv.reader(open(WORD_FREQUENCY_CSV_FILENAME, encoding="utf-8"), delimiter=",")
file2reader = csv.reader(open(INVERSE_DOCUMENT_FREQUENCY_CSV_FILENAME, encoding="utf-8"), delimiter=",")

def is_number(s):
    try:
        float(s)
        return True
    except ValueError:
        return False

#skip headers
header1 = next(file1reader) #header
header2 = next(file2reader) #header
with open(TF_IDF_CSV_FILENAME, 'w', encoding="utf-8", newline='') as csvfile:
    writer = csv.writer(csvfile, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
    writer.writerow(header1)
    for row1, row2 in zip(file1reader, file2reader):
        rowOut = []
        iterrow1 = iter(row1)
        rowOut.append(next(iterrow1))
        for entry in iterrow1:
            entry = float(entry) * float(row2[1])
            rowOut.append(entry)
        writer.writerow(rowOut)
    
print("Done.")