如何在python中将命名结构更改为CSV



我正试图更改从SQL查询创建的CSV文件上打印出来的名称。我希望文件名看起来像yyyyddmm_name "使用年月日捕获其创建之日的相应日期。目前我正在使用pandas和datetime,这并没有给我正确的名称结构。你能建议一个替代方案吗?谢谢你对这件事的帮助。欢呼。

df。to_csv(r datetime.now()"Name "+ ".csv", index=False)

import time
file_name = time.strftime("%Y%m%d"+"_Name")
print(file_name)

适合你的情况

import time
file_name = time.strftime("%Y%m%d"+"_Name")
save_to_path = r'C:UsersMyPCDesktop' #this is where your .csv file will be saved
df.to_csv(save_to_path+"\"+file_name+ ".csv", index=False)

最新更新