i have a large data file . THE DATA WHICH I WOULD TO EXTRACT IN FORMAT
GROUP NUMBER 1
N BIRTH CODE TEST 1 TEST 2 TEST 3 TOTAL ID
1 28-4-1986 0000000001 0.000000000 0.000000000 0.000000000 0.000000000 1019892555
2 29-4-1986 0000000001 0.000000000 0.000000000 0.000000000 0.000000000 1019892555
3 28-4-1986 0000000001 0.000000000 0.000000000 0.000000000 0.000000000 1019892555
TOTAL=
GROUP NUMBER 2
N BIRTH CODE TEST 1 TEST 2 TEST 3 TOTAL ID
1 28-4-1986 0000000001 0.000000000 0.000000000 0.000000000 0.000000000 1019892555
2 29-4-1986 0000000001 0.000000000 0.000000000 0.000000000 0.000000000 1019892555
3 28-4-1986 0000000001 0.000000000 0.000000000 0.000000000 0.000000000 1019892555
TOTAL=
GROUP NUMBER 3
N BIRTH CODE TEST 1 TEST 2 TEST 3 TOTAL ID
1 28-4-1986 0000000001 0.000000000 0.000000000 0.000000000 0.000000000 1019892555
2 29-4-1986 0000000001 0.000000000 0.000000000 0.000000000 0.000000000 1019892555
3 28-4-1986 0000000001 0.000000000 0.000000000 0.000000000 0.000000000 1019892555
TOTAL=
WHERE GROUP NUMBER CHANGE FROM 1 TO 1000
# in real it is up to 10000000 so it is difficult to defined each group number
I WANT TO EXTRACT INTO TEXT FILE The total column for group number
1 51 101 151 201 251 301 351 401 451 501 551 601 651 701 751 801 851 901 951.
i write code:
with open('data.txt') as infile, open('total.txt', 'w') as outfile:
copy = False
for line in infile:
if line.startswith("GROUP NUMBER 1"):
copy = True
elif line.startswith("TOTAL"):
copy = False
elif line.startswith("GROUP NUMBER 51"):
copy = True
elif line.startswith("TOTAL"):
copy = False
elif line.startswith("ZONE NUMBER 101"):
copy = True
elif line.startswith("TOTAL"):
copy = False
#UNTIL REACH 951
continue
outfile.write(line)
continue
elif copy:
outfile.write(line)
my questions
1- can I let the group number change automatic by do?
2- can I extract only the column total not all data in between ?
thanks
user1796483 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.