title: Python: How to write to CSV and append date from a DataFrame to the filename
body: <p>I am using the following method to write to a csv file with the date appended to the filename. </p>
  
  <pre><code>outpath = r'C:\test'
  filename = "filename_"+(time.strftime("%Y%m%d")+".csv")
  
  df.to_csv(outpath + "\\" + filename)
  
  
  print outpath + "\\" + filename
  
  C:\test\filename_20140621.csv
  </code></pre>
  
  <p>But I have a problem when the routine crosses midnight and the date added is then incorrect.</p>
  
  <p>I have the correct date in a DataFrame df, like this:</p>
  
  <pre><code>df['Date/Time'].head()
  Out[54]:
  
  0   2014-06-20
  1   2014-06-20
  2   2014-06-20
  3   2014-06-20
  4   2014-06-20
  Name: Date/Time, dtype: object
  </code></pre>
  
  <p>I would like to use this date in the filename, but I can't find the correct way to reference it</p>
  
  <p>For example, I put this date in a new dataframe named 'date' with just the one column: </p>
  
  <pre><code>date = pd.to_datetime(df['Date/Time'])
  date.head()
  
  Out[15]:
  
  0   2014-06-20
  1   2014-06-20
  2   2014-06-20
  3   2014-06-20
  4   2014-06-20
  Name: Date/Time, dtype: datetime64[ns]
  </code></pre>
  
  <p>and tried the following:</p>
  
  <p>filename = "filename_"+ date._slice(slice(1))+".csv")</p>
  
  <p>...and various similar things.</p>
  
  <p>Can anybody show me how to set the filename to include the date from the DataFrame?</p>
  
  <p>Any help much appreciated.</p>