Note that there are some explanatory texts on larger screens.

plurals
  1. POgenerating a single outfile after analyzing multiple files in python
    primarykey
    data
    text
    <p>i have multiple files each containing 8/9 columns. </p> <p>for a single file : I have to read last column containing some value and count the number of occurrence of each value and then generate an outfile. </p> <p>I have done it like: </p> <pre><code>inp = open(filename,'r').read().strip().split('\n') out = open(filename,'w') from collections import Counter C = Counter() for line in inp: k = line.split()[-1] #as to read last column C[k] += 1 for value,count in C.items(): x = "%s %d" % (value,count) out.write(x) out.write('\n') out.close() </code></pre> <p>now the problem is it works fine if I have to generate one output for one input. But I need to scan a directory using <code>glob.iglob</code>function for all files to be used as input. And then have to perform above said program on each file to gather result for each file and then of course have to write all of the analyzed results for each file into a single OUTPUT file. </p> <p>NOTE: During generating single OUTPUT file if any value is found to be getting repeated then instead of writing same entry twice it is preferred to sum up the 'count' only. e.g. analysis of 1st file generate: </p> <pre><code>123 6 111 5 0 6 45 5 </code></pre> <p>and 2nd file generate: </p> <pre><code>121 9 111 7 0 1 22 2 </code></pre> <p>in this case OUTPUT file must be written such a way that it contain: </p> <pre><code>123 6 111 12 #sum up count no. in case of similar value entry 0 7 45 5 22 2 </code></pre> <p>i have written prog. for single file analysis BUT i'm stuck in mass analysis section. please help.</p>
    singulars
    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.
    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