I use the following lines of code to loop over different files in a folder:
import os
files_in_folder_1 = [os.path.join(path1, f) for f in os.listdir(path1) if os.path.isfile(os.path.join(path1, f))]
files_in_folder_2 = [os.path.join(path2, f) for f in os.listdir(path2) if os.path.isfile(os.path.join(path2, f))]
for file1, file2 in zip(files_in_folder_1, files_in_folder_2):
with open(file1) as f1, open(file2) as f2:
dftask = pd.read_csv(file2)
dfresource = pd.read_csv(file1)
At the end of all operations I want to save the files in another directory with the same filename. However how should I do that? I use this:
dftask.to_csv(r'path\file1.csv')
dfresource.to_csv(r'path\file2.csv')
However when using this line of code the csv. file is constantly overwritten inside the loop over all files.
What is the solution?