Python Forum
Script to average 2 columns in .csv file, and print results to the file name. - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Script to average 2 columns in .csv file, and print results to the file name. (/thread-5095.html)



Script to average 2 columns in .csv file, and print results to the file name. - Manveer_Dhillon - Sep-18-2017

Hi everyone, I'm running a test which outputs numerous .csv files (around 12). I need to average out the data in column G (7) and H (8). I'd then like to have the averages and the title of column 'G (7) CMAA' and column 'H (8) TAA' printed to show up at the respective .csv file name.

ex

Original .csv file output from my benchmark:
TestResult-Run1
TestResult-Run2
TestResult-Run3
etc..

What I would like for my script to do:
TestResult-Run1_CMAA-3.46_TAA-4.67.csv
TestResult-Run2_CMAA-3.89_TAA-3.49.csv
TestResult-Run3_CMAA-3.45_TAA-4.21.csv
etc..

Is this possible with a .bat script?


RE: Script to average 2 columns in .csv file, and print results to the file name. - Larz60+ - Sep-18-2017

What's this got to do with python?


RE: Script to average 2 columns in .csv file, and print results to the file name. - Manveer_Dhillon - Sep-18-2017

Sorry, I'm using a .bat file to generate the .csv files. But I would like to have python do the averaging and renaming of the files if it's possible.


RE: Script to average 2 columns in .csv file, and print results to the file name. - Larz60+ - Sep-18-2017

You can do this with python quite easily actually.
Not sure of the best way to go about it, perhaps load into a list so you can add columns.
This will work if rows are symmetrical.