To export a CSV dataset to a different directory in Python, you can use the following code:
main.py549 chars19 lines
Replace 'path/to/source_file.csv'
with the actual path to your source CSV file and 'path/to/destination_directory/'
with the actual path to the directory where you want to export the CSV file.
This code uses the shutil.copyfile
function to copy the source CSV file to the destination directory. os.makedirs
is used to create the destination directory if it doesn't exist.
Make sure you have the os
and shutil
modules imported at the beginning of your script.
This code will create a new file named destination_file.csv
in the specified destination directory, containing the same data as the source CSV file.
gistlibby LogSnag