python - 代码问题(将 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'
解决方案
就像许多特殊字符一样,/
字符也不允许出现在 Windows 中的文件或文件夹名称中。我认为这是你的问题。
推荐阅读
- r - 在 R 中查找每个客户端的最新条目
- awk - 如何获取数据,然后通过 wk 将其转换为日期特定的行?
- python - 散景:如何单击并拖动以显示点之间的位移
- javascript - 有什么方法可以在 tableau Dashboard 上执行点击操作
- asp.net-core - 如何远程调试在 IIS 中发布的 ASP.NET Core webAPI
- mongodb - 在文档中存储表达式/条件
- amazon-web-services - Terraform 错误 EntityAlreadyExists:名为 iam_for_lambda 的角色已存在
- python - 如何打印一个字符串,显示字符串中每个字符重复的次数?
- javascript - 自定义 CTA 按钮插件 CK5Editor
- python - 如何持续交付部署在 Azure 中的 Python 函数应用程序?