How to change the naming structure to a CSV in python

Question:

I am trying to change the name that is printed out on a CSV file that I am creating from an SQL Query. I would like the file name to look like this yyyyddmm_"name". With the year day month capturing the corresponding date on the day of its creation. At the moment I am using pandas and datetime, this is not giving me the correct name structure. Can you sugest an alternative. Thank you for your help with this matter. Cheers.

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

Asked By: Johnny Quest

||

Answers:

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

for your case

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)
Answered By: Murari Mahaseth