如何将datafram转为excel并存储到指定生成的动态文件夹

    # 定义时间标签
    time_label = str(datetime.date.today().strftime('%Y%m'))
    path = time_label
    # 创建文件夹
    if not os.path.exists(path):
        os.mkdir(path)
    # 创建生成文件路径
    new_path = os.path.join(os.getcwd(), path)
    writer = pd.ExcelWriter('Combine_demand_' + time_label + '.xlsx')  # 使用目标文件名创建一个ExcelWriter对象
    d3.to_excel(writer, sheet_name='Combine_demand_' + time_label)  # to_excel方法将cama_list转换成excel文件格式
    writer.save()  # 保存d3.xlsx文件
    print('Combine_demand.xlsx创建成功')

如上面python代码所示:需要将d3转成excel后存入到新建的以time_label命名的文件夹中,现在的代码下,excel文件是自动生成在程序的当前文件夹,怎么写才能让他在生成excel的时候自动进入新生成的time_label文件夹中呢?忘大佬们指点迷津

在writer那行,可以写成路径加上文件名即可,即:writer = pd.ExcelWriter(os.path.join(new_path,'Combine_demand_' + time_label + '.xlsx')) ,如果想按分钟来保存数据的话,time_label 写成: time_label=datetime.datetime.now().strftime('%Y%m%d%H%M')