This is the code I have now
csv_final = [['', 'appeltaart', 'appelstruif', 'amandelbeschuit', 'brood'], ['appel', 3.0, 4.0, 0.0, 0.0], ['gaar', 2.0, 2.0, 0.0, 1.0], ['schotel', 2.0, 4.0, 0.0, 0.0],
['amandel', 0.0, 0.0, 4.0, 0.0],
['deeg', 1.0, 0.0, 2.0, 5.0], ['brood', 0.0, 0.0, 0.0, 1.0], ['suiker', 0.0, 2.0, 2.0, 0.0]]
query = ["appel", "deeg"]
def up_part(query, csv_final, document_vector_lijst):
matrix = []
for j in range(1, len(csv_final)):
product = 0
if csv_final[j][0] in query:
for i in range(1, len(csv_final[0])):
product += csv_final[j][i]
matrix.append(product)
return matrix
The output I need is the total of each column, but only for the rows that are in the query. The expected output:
[4.0, 4.0, 2.0, 5.0]
The output I get right now:
[7.0, 0, 0, 0, 8.0, 0, 0]
Does someone have a clue on how to fix this because I am lost. We are not allowed to use libraries like NumPy to do this.