I have a large data file that I want to edit a bit. I'm checking if the value in a certain column (column 8 in this case) has the same value in multiple lines, and if it reaches the same amount of lines as my "multiplicity" variable I'm saving those lines into a new array. If however this amount is not reached, I want to change the value in another column (column 5) for the lines checked to the amount of lines reached (i.e. my "count" variable). This is where my code is not working.
multiplicity=7
complete_systems=[]
for i in range(len(matching_rows)):
count = 0
value=matching_rows[i][8]
for j in range(len(matching_rows)):
if matching_rows[j][8]==value:
count+=1
if count ==multiplicity:
complete_systems.append(matching_rows[i])
else count for matching_rows[i][5] in matching_rows:
complete_systems.append(matching_rows[i])
where matching_rows is my array. Example lines:
[memmap(['K00806.02', '60.32494216', '12.19', '89.83', '0.2998', '5', '22',
'0.8670', '0.9860', '347.20'],
dtype='<U12'),
memmap(['K00806.01', '143.2063047', '8.9', '89.83', '0.5336', '5', '9',
'0.8670', '0.9860', '138.80'],
dtype='<U12'),
memmap(['K00232.05', '56.2590881', '2.22', '89.97', '0.287', '5', '22',
'1.1910', '0.9950', '29.70'],
dtype='<U12'),
So the code works up until the ELSE part, which just returns an Invalid Syntax error. I don't have much experience with programming so would love some hints!
This seems to have done the job!
if count ==multiplicity:
complete_systems.append(matching_rows[i])
else:
matching_rows[i][5]=count
complete_systems.append(matching_rows[i])