当我以 Excel 格式(“*.xlsx”)保存数据框时,我想在 Excel 文件名中添加时间戳。
如何在使用 Pandas 保存文件时以 Excel 格式保存时将运行时间戳添加到数据框?谢谢
最佳答案
您可以使用datetime模块。它是 the python standard library 之一, 您可以通过 pd.datetime
访问它如下所示。
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()
您可以查看format code table详情。
关于Pandas 在 Excel 中保存数据框时将时间戳添加到文件名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36466372/