Note that there are some explanatory texts on larger screens.

plurals
  1. POReading three files and writing shared items to a new file using Python
    primarykey
    data
    text
    <p>I have three text files. <br/>Two files (a.txt, b.txt) are formatted in the same way (> 100000000 rows, three columns of data) and <br/>one is union file from first column of both a.txt and b.txt. <br/> <br/>a.txt ('r')</p> <pre><code>MARCH2_MARCH2 2.3 0.1 MARCH2_MARC2 -0.22 0 MARCH2_MARCH5 -0.3 0.3 MARCH2_MARCH6 -1.4 0 MARCH2_MARCH7 0.1 0 MARCH2_SEPT2 -1.0 0 MARCH2_SEPT4 0.8 0 </code></pre> <p>b.txt ('r')</p> <pre><code>MARCH2_MARCH2 2.2 0 MARCH2_MARCH2.1 0.2 0 MARCH2_MARCH3 -0.4 0.1111111 MARCH2_MARCH5 -0.3 0 MARCH2_MARCH6 -0.6 0 MARCH2_MARCH7 1.2 0 MARCH2_SEPT2 0.2 0 </code></pre> <p>c.txt ('r')</p> <pre><code>MARCH2_MARCH2 MARCH2_MARCH2.1 MARCH2_MARC2 MARCH2_MARCH5 MARCH2_MARCH6 MARCH2_MARCH7 MARCH2_SEPT2 MARCH2_SEPT4 MARCH2_MARCH3 </code></pre> <p>From these files I'd like to write new files as follows. <br/> That is, insert two values within second and third column of each text file to the corresponded row which contains same value within first column (a[0] == c[0] or b[0] == c[0]). <br/>Thus, the total number of columns in new file might be five. If there is no matched value, I'd like to just insert "NA". </p> <p>new.file ('w')</p> <pre><code>MARCH2_MARCH2 2.3 0.1 2.2 0 MARCH2_MARCH2.1 NA NA 0.2 0 MARCH2_MARC2 -0.2 0 NA NA MARCH2_MARCH5 -0.3 0.3 -0.3 0 MARCH2_MARCH6 -1.4 0 -0.6 0 MARCH2_MARCH7 1.2 0 1.2 0 MARCH2_SEPT2 -1.0 0 0.2 0 MARCH2_SEPT4 0.8 0 NA NA MARCH2_MARCH3 NA NA -0.4 0.1111111 </code></pre> <p>I am looking for a solution and have tried something different including dictionary based parsing. Unfortunately, I am still new to python and all codes I made did not work properly. Please, give me your hand. <br/> Thank you so much in advance.</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