首页 > 解决方案 > 代码问题(将 datetime.strftime wehn 导出数据框添加到新 excel 的名称路径)

问题描述

我一直在尝试在将数据框导出到 Excel 时将日期添加到文件名中。但不是创建 excel 文件,而是搜索具有该名称的文件,而不是创建具有该名称的文件。

'''Python

     datestring= datetime.strftime(datetime.now(),'%m/%d/%Y')
     export_excel=df_vacias.to_excel(r"the path {0}".format("vacias_" 
     datestring +'.xlsx',index=None, header=True))

错误

    self.fp = io.open(file, filemode)

    FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\(the user)\\Desktop\\vacias_09/19/2019.xlsx'

我希望创建此文件 'C:\Users\(the user)\Desktop\vacias_09/19/2019.xlsx'

标签: pythonpandasdatetime-format

解决方案


就像许多特殊字符一样,/字符也不允许出现在 Windows 中的文件或文件夹名称中。我认为这是你的问题。


推荐阅读