I am writing the output of my code to the .csv file. There are three directories each directory contains 50-files. I want to write the output of each directory files in different column. LIKE;
group1 group2 group3
file1 1445 89 87
file2 1225 100 47
file3 650 120 67
file4 230 140 97
I have following code to do so,
from collections import Counter
import glob
import os
out= open( 'output.csv','a')
out.write (';''group-1')
out.write (';''group-2')
out.write (';''group-3')
out.write('\n')
i = 1
while i<=50:
out.write( "file-%d" %i )
out.write('\n')
i+=1
i=1
path = 'group/group-*-files/*.txt'
files=sorted(glob.glob(path))
c=Counter()
for filename in files:
for line in open(filename,'r'):
c.update(line.split())
for item in c.items():
oi=("{}\t{}".format(*item))
out_array = oi.split()
if out_array[0]=='00000000':
out.write(out_array[1])
out.write('\n')
c.clear()
The problem I am getting and did not able to solve, the answer starts writing in the first column after file number 50
file48
file49
file50
1445
1225
..
I want to write first 50 answers under group1 column, next 50 in group2 and last 50 in group3
final output looks like,
group1 group2 group3
file1 145 89 87
file2 850 100 47
file3 650 120 67
file4 230 140 97