Currently I am working on one directory and my Python file(.ipynb) file is stored in the same directory.
Directory currently I am working = "C:\Users\XYZ\Desktop\ABC\Data Science"
After working on a data set I am dumping my data frame into new folder = "C:\Users\XYZ\Desktop\ABC\Data Science\Dataset"
.
I have a requirement where I have to save the data based on Date and time.
I have used below method
TodaysDate = time.strftime("%d-%m-%Y-%H-%M-%S")
excelfilename_pass = TodaysDate ".csv"
passed_data.to_csv(excelfilename_pass)
But the above code is getting saved in "C:\Users\XYZ\Desktop\ABC\Data Science"
this folder whereas I want the data frame to be saved in "C:\Users\XYZ\Desktop\ABC\Data Science\Dataset"
folder.
Any help would be appreciated.
CodePudding user response:
Try using the full path
folder_path = r"C:\Users\XYZ\Desktop\ABC\Data Science\Dataset"
file_path = os.path.join(folder_path, "{}.csv".format(time.strftime("%d-%m-%Y-%H-%M-%S")))
passed_data.to_csv(file_path )
CodePudding user response:
If your code is currently in the Data Science folder, I would simply add the dataset
to your file path.
So excelfilename_pass = "dataset/" TodaysDate ".csv"