i have 3 csv files named file1, file2, file3. Each CSV is filled with 3 Columns and 5653 rows:
1 0 -95
2 0 -94
3 0 -93
...
51 0 -93
0 1 -92
1 1 -91
2 1 -90
..
First column is a X variable 2nd is a y variable, 3rd is a measured value from which I want to have the mean.
What I want to do is:
- read first row of file 1
- read first row of file 2
- read first row of file 3 and then count the mean of the measured value.
So for example:
file1 row1 -98
file2 row1 -97
file3 row1 -95
mean 96,666666667
i want to write that mean into a new csv file with the following format
1,0,mean_of_row1 (which would be 96,666666667)
2,0,mean_of_row2
3,0,mean_of_row3
4,0,mean_of_row4
currently im able to calculate the mean of the measurement column of each file and store it as a row in a results file
import pandas as pd
import numpy as np
csv_file_list = ["file1.csv", "file2.csv", "file3.csv"]
result_csv = "result.csv"
with open(result_csv, 'wb') as rf:
for idx, csv_file in enumerate(csv_file_list):
csv_data = pd.read_csv(csv_file).values
mean_measured = np.mean(csv_data[:, 2])
rf.write(','.join([str(0), str(idx), str(mean_measured)+"\n"]))
But how can fulfill my intention? Thanks so far