I have a tab delimited data text file in the following format:
Depth Temp Salinity
0.30 28.30 31.90
0.30 28.30 31.90
0.30 28.20 31.90
0.30 28.20 31.90
0.40 28.20 32.00
0.40 28.00 32.00
0.50 28.00 31.90
0.60 28.00 32.00
0.70 27.90 32.00
0.60 27.90 32.10
What I want to achieve is to obtain any lines where there are duplicate values in the Depth column and put them into a list/s. Then from that list/s I will average these values for each column (not averaging the Depth column), sort the values by Depth, and then output all this back into the original data file format. So in the example file above, the output would be:
Depth Temp Salinity
0.30 28.25 31.90
0.40 28.10 32.00
0.50 28.00 31.90
0.60 27.95 32.05
0.70 27.90 32.00
I understand I need to use .readlines() to grab the relevant lines, but how do I only grab duplicate lines?
Thanks in advance!
You should use a dictionary where the key is the depth.