0

Good morning,

Why I cannot append date to a filename when saving a dataframe to excel? Here is my code.

date = '24/12/2020'
datetime_object = datetime.strptime(date, '%m/%d/%Y')

writer = pd.ExcelWriter('Weekly_Report_'+date+'.xlsx', engine='xlsxwriter')
df.to_excel(writer,sheet_name='Scheduled Report', index=False)
writer.save()

The error is:

FileNotFoundError: [Errno 2] No such file or directory: 'Weekly_Report_24/12/2020.xlsx'
MMarie
  • 35
  • 6

1 Answers1

2

You are attempting to include forward slashes in the file name which is prohibited. Use some other character such as '-' as a separator in the date (e.g. 24-12-2020).

Read more - Is it possible to use “/” in a filename?