0

I have code that compares 2 csv files and generates an output from them. I have around 50 csv files to compare. In the end i will have 25 csv as output. Is there a loop function which i can just run one code and generate 25 output?

All the filenames and their comparison names are in one excel sheet which can help.

FileA FileB    outputname=FileAB
FileC FileD    outputname=FileCD
FileE FileF    outputname=FileEF

My code starts like this :

import pandas as pd
import numpy as np

file1 = 'oldfile.csv'
file2 = 'newfile.csv'

df1 = pd.read_csv(file1)
df2 = pd.read_csv(file2)

and at the end i save the csv file:

df.to_csv(file_name, index=False)
Lea123
  • 15
  • 4
  • Welcome to Stack Overflow, Do you have a question? – The Singularity Feb 24 '21 at 17:08
  • @Luke Is there a loop function which i can just run one code and generate 25 output as i mentioned above ? – Lea123 Feb 24 '21 at 17:22
  • @Lea123 Your approach is correct. You need to read the file names from the CSV file and inside the loop, you need to compare files and generate a new loop. If you have any specific questions please ask. Don't expect the complete answer from here. – Afiz Feb 24 '21 at 17:26
  • put the file names in a list. Then iterate through the list by two's. The first file name would be i and the second would be i+1 most likey. https://stackoverflow.com/questions/2990121/how-do-i-loop-through-a-list-by-twos – Hooded 0ne Feb 24 '21 at 19:52

0 Answers0