I'm having trouble finding the correct way to mask specific values from a column after reading a csv file. I found how to create a masked array after creating an array directly in the code.
If I'm reading a file with
data = np.genfromtxt("file")
and I want to mask all the "NA" entries from the column labeled "Age", how would I write that out? Thanks in advance!
You could create
np.ma.array
and then usemean
to get the desired result. The mask in thenp.ma.array
could be set to the result ofarr.isnan()
which would mask allNAN
valuesHere is the link for reference:
https://numpy.org/doc/stable/reference/generated/numpy.ma.mean.html