I have a numpy array:
A = array([['id1', '1', '2', 'NaN'],
['id2', '2', '0', 'NaN']])
I also have a list:
li = ['id1', 'id3', 'id6']
I wish to iterate over the array and the list and where the first element in each row of the array is not in the list, then delete that entire row from the array.
My code to date:
from numpy import *
for row in A:
if row[0] not in li:
delete(A, row, axis = 0)
This returns the following error:
ValueError: invalid literal for int() with base 10: 'NaN'
The type of all elements in each row is str(), therefore I do not understand this mention of int() in the error.
Any suggestions?
Thanks,
S 😉
Just generating a new array is no option?