Read data from text file, into numpy array in python
<p>I want to read the file of below format into numpy array in python. </p>

<pre><code>ADIDGoogle#8a65c466-****-4a7e-****-0836c8884dae 2016-06-01  17:55:53
ADIDGoogle#8a65c466-****-4a7e-****-0836c8884dae 2016-06-01  17:55:53
ADIDGoogle#8a65c466-****-4a7e-****-0836c8884dae 2016-06-01  17:55:53
ADIDGoogle#8a664a70-****-4103-****-4f7e6cb9a33a 2016-06-01  13:20:02
ADIDGoogle#8a664a70-****-4103-****-4f7e6cb9a33a 2016-06-01  13:35:48
ADIDGoogle#8a664a70-****-4103-****-4f7e6cb9a33a 2016-06-01  13:26:20
ADIDGoogle#8a664a70-****-4103-****-4f7e6cb9a33a 2016-06-01  13:31:12
ADIDGoogle#8a664a70-****-4103-****-4f7e6cb9a33a 2016-06-01  13:19:17
ADIDGoogle#8a664a70-****-4103-****-4f7e6cb9a33a 2016-06-01  13:20:02
ADIDGoogle#8a664a70-****-4103-****-4f7e6cb9a33a 2016-06-01  13:36:39
ADIDGoogle#8a664a70-****-4103-****-4f7e6cb9a33a 2016-06-01  13:31:12
ADIDGoogle#8a664a70-****-4103-****-4f7e6cb9a33a 2016-06-01  13:35:48
</code></pre>

<p>it is having three columns separated by '\t'.
i want to read this into numpy array with two columns where the date and time in to one column and id in another column.</p>

<p>I tried using </p>

<pre><code>Data = np.loadtxt(filename,dtype='string',usecols=(1,2),delimiter="\t")
</code></pre>

<p>but it is giving me error as : </p>

<pre><code>IndexError: list index out of range
</code></pre>

<p>You can read via <code>genfromtxt</code> line-by-line</p>

<pre><code>import numpy as np

fname = "./data.txt"

with open(fname, 'r') as f:
    data = np.genfromtxt(f,comments="!",dtype="string",usecols=(1,2))

print data
</code></pre>

python arrays numpy