
I am using loadtxt and I have missing values that are show up as N/A.
I get a,
ValueError: invalid literal for float(): N/A
Is there a way to ignore these?

you can use the 'converters' keyword in numpy.loadtxt. first define a function to convert a string in a float, that can handle your 'N/A' entries:
def converter(x): if x == 'N/A': return numpy.nan else: return float(x)
then use:
numpy.loadtxt('test.dat', converters={1:converter,2:converter})
array([[ 1., 2., NaN, 4.], [ 1., NaN, 3., 4.]])
where the file test.dat I used looks like this: 1 2 N/A 4 1 N/A 3 4
hth, L.
On Sun, Jul 13, 2008 at 09:50:24AM -0400, Bryan Fodness wrote:
I am using loadtxt and I have missing values that are show up as N/A.
I get a,
ValueError: invalid literal for float(): N/A
Is there a way to ignore these?
Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
participants (2)
-
Bryan Fodness
-
Lorenzo Bolla