Mask specific values in column after reading csv file

386 Views Asked by At

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!

1

There are 1 best solutions below

0
On

You could create np.ma.array and then use mean to get the desired result. The mask in the np.ma.array could be set to the result of arr.isnan() which would mask all NAN values

Here is the link for reference:

https://numpy.org/doc/stable/reference/generated/numpy.ma.mean.html