Convert date from yyyymmddHHMMSS format
<p>I would like to read two columns (columns 0, 4) of the following ascii file and plot them. One contains the date in yyymmddHHMMSS format which I would like to covert to a date number.</p>

<pre><code># Date          RMS.I   RMS.Q   Cal.I   Cal.Q      
20121220220000 1.45485 1.42051 1.26393 1.29448
20121220230000 1.43377 1.39987 1.26803 1.29874
20121221000000 1.44888 1.41472 1.24759 1.27771
</code></pre>

<p>I have been using numpy.loadtxt but it reads all columns as float.</p>

<pre><code>mydate, myvar = np.loadtxt('infile.txt', comments="#", skiprows=1, usecols=(0,4), unpack=True)
</code></pre>

<p>You can import as a <a href="http://docs.scipy.org/doc/numpy/user/basics.rec.html" rel="nofollow">structured array</a> as follow:</p>

<pre><code>mydate, myvar = np.loadtxt('infile.txt', comments="#", skiprows=1, usecols=(0,4), unpack=True, dtype=[('date', '|S10'), ('floatmio', float)])
</code></pre>

<p>it will import the date as <code>str</code> in <code>mydate</code> array. And then you can use <a href="https://docs.python.org/2/library/datetime.html" rel="nofollow"><code>datetime</code></a> library on the single array entries to handle them as follow:</p>

<pre><code>import datetime
dates = [datetime.datetime.strptime(x, '%Y%m%d%H') for x in mydate]
</code></pre>

python numpy