gpt4 book ai didi

python - 代码有问题(添加 datetime.strftime wehn 导出数据框到新 excel 的名称路径)

转载 作者:太空宇宙 更新时间:2023-11-03 20:23:21 25 4
gpt4 key购买 nike

我一直在尝试将数据框导出到 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\(用户)\Desktop\vacias_09/19/2019.xlsx”

最佳答案

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

关于python - 代码有问题(添加 datetime.strftime wehn 导出数据框到新 excel 的名称路径),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58014745/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com