Dear friends,
I need again your help for a new challenge ;)
I have a number of files with 5 columns of values (comma separated). I would like to find a way to the values in the first 2 columns and compare them with the first 2 columns of the next file and when they match I need to print (or save to file) the complete line in first and second file.
I guess an example will make things easier.

File1
82647.675915,138208.736325,1618.72,-1195.28,1
82642.4095612,138203.777175,686.08,-1420.4,1
82648.3342092,138212.949408,1918.88,-921.92,1
82647.1053933,138211.193956,1704.48,-996.96,1
82646.5787579,138209.657937,1554.4,-1093.44,1
82649.38748,138210.316231,1908.16,-1109.52,1
82643.6822634,138204.962104,927.28,-1372.16,1
82645.2621695,138208.824097,1361.44,-1109.52,1
82641.8829258,138202.504473,519.92,-1511.52,1
...

FileN
82647.1053933,138211.193956,180.48,-22.96,1
82646.5787579,138209.657937,54.4,-55.44,1
82645.38748,138210.316231,2010.6,-809.52,1
...

So I will take 82647.675915,138208.736325 first 2 columns from the first file and compare it with of 82647.1053933,138211.193956 then 82646.5787579,138209 then 82649.38748,138210.316231 of FileN.

In the above example, the result should be:

File1
82647.1053933,138211.193956,1704.48,-996.96,1
82646.5787579,138209.657937,1554.4,-1093.44,1

File N
82647.1053933,138211.193956,180.48,-22.96,1
82646.5787579,138209.657937,54.4,-55.44,1

I will need to make the comparison of File1 with File2, File2 with File3 and so on.

Thank you for your precious help,
Gianluca

Recommended Answers

All 4 Replies

My first suggestion is to look into the csv module in the standard library. It may save you from reinventing the wheel WRT comma-spearated value files.

Dear Schol-R-LEA,
I don't seem to find any reference to matching values. My problem is not so much to get the values, it is more about finding same values in different files.
Thank you anyway for your help,
G.

Thank you pytony,
indeed it looks close enough to my case, but my limited knowledge with python (and math) doesn't allow me still to adapt the case to my dataset.
I will work on it and try to get out what I need but I would appreciate any hints or... starting directions.
Thanks again,
G.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.