Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pandas Add Timestamp to file name during saving Data Frame in Excel

While i am saving Data Frames in Excel format ("*.xlsx"), i would like to add time stamp to Excel file name.

How can i add run time time stamp to Data Frame while saving in Excel format while saving file using Pandas? Thank you

like image 358
Felix Avatar asked Sep 03 '25 02:09

Felix


1 Answers

You can use datetime module. It's one of the python standard library, you can access it by pd.datetime like below.

import pandas as pd

writer = pd.ExcelWriter('output_{}.xlsx'.format(pd.datetime.today().strftime('%y%m%d-%H%M%S'))) 
df1.to_excel(writer,'Sheet1')
df2.to_excel(writer,'Sheet2') 
writer.save()

And you can check format code table for the detail.

like image 139
su79eu7k Avatar answered Sep 05 '25 19:09

su79eu7k