Note that there are some explanatory texts on larger screens.

plurals
  1. POEfficient Python way to process two huge files?
    primarykey
    data
    text
    <p>I am working on a problem where I have to find if a number falls within a certain range. However, the problem is complicated due to the fact that the files I am dealing with have hundreds of thousands of lines. </p> <p>Below I try to explain the problem in as simple a language as possible. </p> <p>Here is a brief description of my input files :</p> <p>File <strong>Ranges.txt</strong> has some ranges whose min and max are tab separated.</p> <pre><code>10 20 30 40 60 70 </code></pre> <p>This can have about 10,000,000 such lines with ranges. </p> <p><strong>NOTE:</strong> The ranges <strong>never</strong> overlap. </p> <p>File <strong>Numbers.txt</strong> has a list of numbers and some values associated with each number. </p> <pre><code>12 0.34 22 0.14 34 0.79 37 0.87 </code></pre> <p>And so on. Again there are hundreds of thousands of such lines with numbers and their associated values.</p> <p>What I wish to do is take every number from <strong>Numbers.txt</strong> and check if it falls within any of the ranges in <strong>Ranges.txt</strong>. </p> <p>For all such numbers that fall within a range, I have to get a mean of their associated values (ie a mean per range). </p> <p>For eg. in the example above in <strong>Numbers.txt</strong>, there are two numbers 34 and 37 that fall within the range 30-40 in <strong>Ranges.txt</strong>, so for the range 30-40 I have to calculate the mean of the associated values of 34 and 37. (i.e mean of 0.79 and 0.87), which is 0.82</p> <p>My final output file should be the <strong>Ranges.txt</strong> but with the mean of the associated values of all numbers falling within each range. Something like :</p> <p><strong>Output.txt</strong></p> <pre><code>10 20 &lt;mean&gt; 30 40 0.82 60 70 &lt;mean&gt; </code></pre> <p>and so on.</p> <p>Would appreciate any help and ideas on how this can be written efficiently in Python. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload