# 定义时间标签
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文件夹中呢?忘大佬们指点迷津