How to read all .csv files from a folder in python?

My folder contains ‘n’ number of .csv files. Each file contains seven columns. I want to find the difference between the maximum and minimum points for a 5th column.

How to find this difference for all the .csv files and write the result in a separate file?

1 Like

You need to obtain the names of the CSV files in your folder. The
os.listdir function or the fnmatch function can obtain these for you.

Then write a loop which iterates over the filenames. Open each and read
it with the csv.reader function.

Collect the values from the fifth column and track the max and min
values. Compare them at the end.

This feels like a homework question: we don’t write code for you because
you will learn little, but we will assist with suggestions and answer
questions if you have partial but not yet working code.

Cheers,
Cameron Simpson cs@cskk.id.au

1 Like

Dear Cameron,

Sorry, sir, it’s not a homework question. I am a research scholar and I am from a science background. I’m newbie to python. For the processing of the simulation data, we are using python. Hope you understand my situation. If you share a snippet of the code that will be a great help for my work.

Best regards,
Sateesh Kandukuri
Research Scholar
Dept. of Physics
BITS Pilani Hyderabad Campus