title: How do I extract a DateTimeIndex for use in a new column?
body: <p>I've extracted the dates from filenames in a set of Excel files into a list of DateTimeIndex objects. I now need to write the extracted date from each to a new date column for the dataframes I've created from each Excel sheet. My code works in that it writes the the new 'Date' column to each dataframe, but I'm unable to convert the objects out of their generator object DateTimeIndex format and into a %Y-%m-%d format.</p>
  
  <p>Link to code creating the list of DateTimeIndexes from the filenames:
  <a href="https://stackoverflow.com/questions/57794275/how-do-i-turn-datefinder-output-into-a-list">How do I turn datefinder output into a list?</a></p>
  
  <p>Code to write each list entry to a new 'Date' column in each dataframe created from the spreadsheets:</p>
  
  <pre><code>for i in range(0, len(df)):
      df[i]['Date'] = (event_dates_dto[i] for frames in df)
  </code></pre>
  
  <p>The involved objects:</p>
  
  <pre><code>type(event_dates_dto)
  &lt;class 'list'&gt;
  
  type(event_dates_dto[0])
  &lt;class 'pandas.core.indexes.datetimes.DatetimeIndex'&gt;
  
  event_dates_dto
  [DatetimeIndex(['2019-03-29'], dtype='datetime64[ns]', freq=None), DatetimeIndex(['2019-04-13'], dtype='datetime64[ns]', freq=None), DatetimeIndex(['2019-05-11'], dtype='datetime64[ns]', freq=None)]
  </code></pre>
  
  <p>The dates were extracted using datefinder: <a href="http://www.blog.pythonlibrary.org/2016/02/04/python-the-datefinder-package/" rel="nofollow noreferrer">http://www.blog.pythonlibrary.org/2016/02/04/python-the-datefinder-package/</a></p>
  
  <p>I've tried using methods here that seemed like they could make sense but none of them are the right ticket: <a href="https://stackoverflow.com/questions/16176996/keep-only-date-part-when-using-pandas-to-datetime">Keep only date part when using pandas.to_datetime</a></p>
  
  <p>Again, the simple for function is working correctly, but I'm unsure how to coerce the generator object into the correct format so that it not only writes to the new 'Date' column but also so that it is is in a useful '%Y-%m-%d' format that makes sense within the dataframe. Any help is greatly appreciated.</p>