title: Fast conversion of time string (Hour:Min:Sec.Millsecs) to float
body: <p>I use pandas to import a csv file (about a million rows, 5 columns) that contains one column of timestamps (increasing row-by-row) in the format Hour:Min:Sec.Millsecs, e.g.</p>
  
  <p>11:52:55.162</p>
  
  <p>and some other columns with floats. I need to transform the timestamp column into floats (say in seconds). So far I'm using </p>
  
  <pre><code>pandas.read_csv  
  </code></pre>
  
  <p>to get a dataframe df and then transform it into a numpy array</p>
  
  <pre><code>df=np.array(df)
  </code></pre>
  
  <p>All the above works great and is quite fast. However, then I use datetime.strptime (the 0th columns are the timestamps)</p>
  
  <pre><code>df[:,0]=[(datetime.strptime(str(d),'%H:%M:%S.%f')).total_seconds() for d in df[:,0]]
  </code></pre>
  
  <p>to transform the timestamps into seconds and unfortunately this turns out to be veryyyy slow . It's not the iteration over all the rows that so slow but</p>
  
  <pre><code>datetime.strptime 
  </code></pre>
  
  <p>is the bottleneck. Is there a better way to do it?</p>