3

I am trying to save a dataframe to Excel and unfortunately I am not getting around the Syntax. I want to save the file to a path and Name it by today date.

df.to_excel(r'\\folderA\folderB\Dokumente\'',today.strftime("%d%m%Y")+'delmedf.xlsx')

Am I doing something wrong with the quote signs?

5
  • You can try change , to + like df.to_excel(r'\\folderA\folderB\Dokumente\' + today.strftime("%d%m%Y")+'delmedf.xlsx'), because you concanecate strings. Commented Feb 25, 2016 at 11:21
  • this works now, but I am getting a ' in front of the filename. '25022016delmedf.xlsx Commented Feb 25, 2016 at 11:23
  • Try remove one ' in the end of '\\folderA\folderB\Dokumente\' Commented Feb 25, 2016 at 11:25
  • removal of one ' results in invalid Syntax Commented Feb 25, 2016 at 11:28
  • please check df.to_excel(r'\\folderA\folderB\Dokumente\'' + dt.datetime.today().strftime("%d%m%Y")+'delmedf.xlsx') Commented Feb 25, 2016 at 11:33

1 Answer 1

4

I think you can try add () to today and + before:

import datetime as dt

print dt.datetime.today().strftime("%d%m%Y")
25022016

df.to_excel(r'\\folderA\folderB\Dokumente\\' + dt.datetime.today().strftime("%d%m%Y")+'delmedf.xlsx')
Sign up to request clarification or add additional context in comments.

4 Comments

I Keep getting the ` '` in front of the filename. '25022016delmedf.xlsx. I am not sure if this is some problem of how to set the backslashes and quotations?
Yes, I see it - try modified solution.
awesome! This is working now. Thanks a lot. The Setting of this backslashes is really a bit odd...
And maybe I found better solution df.to_excel(r'\\folderA\folderB\Dokumente' + '\\' + dt.datetime.today().strftime("%d%m%Y")+'delmedf.xlsx')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.