top of page


The goal of this project is to merge data between two files. There are 4 files included.

primary.txt - the file to merge

secondary.txt - the file to merge - example on how to read/write to files using python. Use this file to run your merge

answer.txt - what your final merge should look like

The Merge

This is what primary.txt looks like. 


This is what secondary.txt looks like. 


Our goal is to add the columns from secondary.txt into the primary.txt file. We would print those results into a new file called results.txt. 


To do this, we compare the first column of both primary.txt and secondary.txt. When the first column of primary.txt is less than the secondary.txt, then we merge the secondary columns. 

This is better explained in visuals, so look at the image below. 


When looking at the first row in secondary.txt (bottom left of image), the first column value is 0.335. We marked that row red.

Now look at rows in primary.txt (top left of image) who's first column value is less than 0.335. We marked those rows in red as well.


What we want to do is add the second and third column -- inside the secondary.txt -- to the primary.txt. This is denoted by the green circle. 

So if you look at results.txt (top right of image), all rows who's first column is less than 0.335 (denoted by red line), have the value "10010 10" added to its columns.

If you look at primary.txt again, all rows who's values are less than 0.639 are denoted by a blue line. We added the second and third column from secondary.txt ("10010 20") to all columns less than 0.639 in results.txt. 

And that's the task! Merge the second and third columns from secondary.txt into the primary.txt file based on the first column value.

Edge case:

The value of the final secondary.txt row is 77.039 (denoted in yellow in bottom left image). There is a point where the primary.txt rows exceed 77.039 (denoted in red in top left image) exceed .

Those rows do not appear on results.txt.

bottom of page