Numpy: Read csv, deal with undefined values
<p>What is the best way to read data from a csv file into a numpy array when some of the values are labelled as 'undefined' as follows:</p>

<pre><code>0.231620,0.00001,444.157
0.225370,--undefined--,1914.637
0.237870,0.0003,--undefined--
</code></pre>

<p>I have a lot of these files that I will have to loop over, and it is fine to assume that an undefined value should be zero.</p>

<p>To read CSV files and replace the values the best way I think it is using Pandas which uses numpy as well</p>

<pre><code>import pandas as pd

df = pd.read_csv('foo.csv', header=None)
df.replace("--undefined--",0.0, inplace=True)
df

         0        1         2
0  0.23162  0.00001   444.157
1  0.22537        0  1914.637
2  0.23787   0.0003         0
</code></pre>

python csv numpy