Pandas delete all rows that are not a 'datetime' type
<p>I've got a large file with login information for a list of users. The problem is that the file includes other information in the <code>Date</code> column. I would like to remove all rows that are not of type <code>datetime</code> in the <code>Date</code> column. My data resembles</p>

<pre><code>df=
Name      Date
name_1    | 2012-07-12 22:20:00
name_1    | 2012-07-16 22:19:00
name_1    | 2013-12-16 17:50:00
name_1    |                4345 # type = 'int'
                                # type = 'float'
name_2    | 2010-01-11 19:54:00 
name_2    | 2010-02-06 12:10:00
...
name_2    | 2012-07-18 22:12:00
name_2    |                4521
...
name_5423 | 2013-11-23 10:21:00
...
name_5423 |                7532
</code></pre>

<p>I've tried modifying the solution to </p>

<p><a href="http://stackoverflow.com/questions/21771133/finding-non-numeric-rows-in-dataframe-in-pandas">finding non-numeric rows in dataframe in pandas?</a> </p>

<p><a href="http://stackoverflow.com/questions/26771471/remove-rows-where-column-value-type-is-string-pandas">Remove rows where column value type is string Pandas</a></p>

<p>and <a href="https://www.quora.com/How-should-I-delete-rows-from-a-DataFrame-in-Python-Pandas" rel="nofollow">How-should-I-delete-rows-from-a-DataFrame-in-Python-Pandas</a> </p>

<p>to fit my needs. </p>

<p>The problem is that whenever I attempt the change I either get an error or the entire dataframe gets deleted</p>

<p>Use <code>pd.to_datetime</code> with parameter <code>errors='coerce'</code> to make non-dates into <code>NaT</code> null values.  Then you can drop those rows</p>

<pre><code>df['Date'] = pd.to_datetime(df['Date'], errors='coerce')
df = df.dropna(subset=['Date'])

df
</code></pre>

<p><a href="http://i.stack.imgur.com/8tdmh.png"><img src="http://i.stack.imgur.com/8tdmh.png" alt="enter image description here"></a></p>

python pandas