1

I'm trying to replace missing values from a csv file, which in my case are identified with a specific string. I'm doing this

data = np.genfromtxt(filename, delimiter=',', autostrip=True, dtype=float, missing_values="ab", filling_values=0.0)  

string "ab" is just an example, and it could be any string which I use to identify missing values. However, when I dump the csv to file, I see nan and not zero.

j-i-l
  • 10,281
  • 3
  • 53
  • 70
Bob
  • 10,741
  • 27
  • 89
  • 143

1 Answers1

1

It is a bug, as long as the filling_value is not 0 it will work numpy 1.8.1:

In [40]:

%%file temp.txt
1,2,3,4,ab
ab,1,2,2,4
Overwriting temp.txt
In [41]:

data = np.genfromtxt('temp.txt', delimiter=',', 
                     autostrip=True, dtype=float, missing_values="ab", filling_values=0.01)  
In [42]:

data
Out[42]:
array([[ 1.  ,  2.  ,  3.  ,  4.  ,  0.01],
       [ 0.01,  1.  ,  2.  ,  2.  ,  4.  ]])
CT Zhu
  • 52,648
  • 17
  • 120
  • 133