How to define format when using pandas to_datetime?
<p>I want to plot RESULT vs TIME based on a <code>testresult.csv</code> file that has following format, and I have trouble to get the TIME column's datatype defined properly.</p>
<pre><code>TIME,RESULT  
03/24/2016 12:27:11 AM,2  
03/24/2016 12:28:41 AM,76  
03/24/2016 12:37:23 AM,19  
03/24/2016 12:38:44 AM,68  
03/24/2016 12:42:02 AM,44  
...
</code></pre>
<p>To read the csv file, this is the code I wrote:
<code>raw_df = pd.read_csv('testresult.csv', index_col=None, parse_dates=['TIME'], infer_datetime_format=True)</code><br />
This code works, but it is extremely slow, and I assume that the <code>infer_datetime_format</code> takes time. So I tried to read in the csv by default first, and then convert the object dtype 'TIME' to datetime dtype by using <code>to_datetime()</code>, and I hope by defining the format, it might expedite the speed.</p>
<pre><code>raw_df =  pd.read_csv('testresult.csv')
raw_df.loc['NEWTIME'] = pd.to_datetime(raw_df['TIME'], format='%m/%d%Y %-I%M%S %p')
</code></pre>
<p>This code complained error:</p>
<blockquote>
<p><code>&quot;ValueError: '-' is a bad directive in format '%m/%d%Y %-I%M%S %p'&quot;</code></p>
</blockquote>