conversion of np.array(dtype='str') in an np.array(dtype='datetime')
<p>I have a very simple python question. I need to transform the string values within an np.array into datetime values. The string values contain the following format: ('%Y%m%d'). Does any one know how to this? 
Here my test data:</p>

<pre><code>date_str = np.array([['20121002', '20121002', '20121002'],
                     ['20121003', '20121003', '20121003'],
                     ['20121004', '20121004', '20121004']])
</code></pre>

<p>I try to convert this array with the pandas library.
Here is my code:</p>

<pre><code>import pandas as pd    
pd.to_datetime(date_str, format="%d%m%Y")
</code></pre>

<p>Please help me there should be a very simple way to convert this and note that I'm a python beginner.</p>

<p>You can create a DataFrame, then <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.apply.html" rel="nofollow"><code>apply</code></a> to it <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.to_datetime.html" rel="nofollow"><code>pd.to_datetime</code></a>:</p>

<pre><code>In [68]: pd.DataFrame(date_str).apply(pd.to_datetime)
Out[68]: 
           0          1          2
0 2012-10-02 2012-10-02 2012-10-02
1 2012-10-03 2012-10-03 2012-10-03
2 2012-10-04 2012-10-04 2012-10-04
</code></pre>

<p>In order to verify the type of the result, here's the type of the first column, for example:</p>

<pre><code>In [73]: pd.DataFrame(date_str).apply(pd.to_datetime).iloc[:, 0].dtype
Out[73]: dtype('&lt;M8[ns]')
</code></pre>

python datetime pandas numpy