title: How to concatenate pandas dataframe date and different time formats to single timestamp?
body: <p>I have two columns in a <code>pandas</code> data frame as outlined below. Notice how some of the <code>EVENT_TIME</code> is in <code>hh.mm.ss</code>, some is in <code>hh:mm:ss AM/PM</code> format. </p>
  
  <p><a href="https://i.stack.imgur.com/sNIc3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/sNIc3.png" alt="enter image description here"></a></p>
  
  <p><strong>When running...</strong></p>
  
  <pre><code>import pandas
  
  df['EVENT_DATE'] = pd.to_datetime(df['EVENT_DATE'], format='%Y%m%d')
  
  print(df['EVENT_DATE'])
  </code></pre>
  
  <p>...I can get <code>EVENT_DATE</code> in a consumable (for my purposes) format (e.g. <code>1999-07-28</code>). </p>
  
  <p><strong>But when running...</strong></p>
  
  <pre><code>df['EVENT_TIME'] = pd.to_datetime(df['EVENT_TIME'], format='%H.%M.%S', errors='coerce')
  df['EVENT_TIME'] = pd.to_datetime(df['EVENT_TIME'], format='%I:%M:%S %p', errors='coerce')
  
  print(df['EVENT_TIME'])
  </code></pre>
  
  <p><strong>...<code>1900-01-01</code> is added to the times and is not being applied to all rows.</strong></p>
  
  <pre><code>1900-01-01 16:40:00
  1900-01-01 15:55:00
  1900-01-01 14:30:00
  1900-01-01 13:26:00
  NaT
  NaT
  NaT
  NaT
  </code></pre>
  
  <p>How do I concatenate the date and times (which include multiple time formats) in a single timestamp?</p>
  
  <p><strong>Edit1:</strong></p>
  
  <p><strong>@Wen-Ben 's solution got me here:</strong></p>
  
  <pre><code>1      19:53:00
  11     14:30:00
  15     16:30:00
  </code></pre>
  
  <p><strong>Then to concatenate EVENT_DATE and EVENT_TIME, I found this (which works):</strong></p>
  
  <pre><code>df['TIMESTAMP'] = df.apply(lambda r : pd.datetime.combine(r['EVENT_DATE'], r['EVENT_TIME']),1)
  </code></pre>
  
  <p><strong>...results in:</strong></p>
  
  <pre><code>1     1999-07-28 19:53:00
  11    2001-07-28 14:30:00
  15    2002-06-07 16:30:00
  </code></pre>
  
  <p><strong>Next I want to get this into ISO8601 format. So I found this (which works):</strong></p>
  
  <pre><code>pd.to_datetime(df['TIMESTAMP']).apply(lambda x: x.strftime('%Y%m%dT%H:%M%SZ'))
  </code></pre>
  
  <p><strong>...results in:</strong></p>
  
  <pre><code>1      19990728T19:5300Z
  11     20010728T14:3000Z
  15     20020607T16:3000Z
  </code></pre>
  
  <p><strong>HERES MY NEW PROBLEM:</strong></p>
  
  <p>Running <code>print(TIMESTAMP)</code> still shows the concatenated versions (e.g. <code>1999-07-28 19:53:00</code>) instead of the ISO version (e.g.<code>19990728T19:5300Z</code>)</p>
  
  <p><strong>How do I get the ISO8601 column "added" to the dataframe?</strong> </p>
  
  <p>Ideally, I want it to take the place of <code>TIMESTAMP</code>. I want it as a transformation of the data, not tacked on as a new column.</p>