I try to select specific fields from my Qdata.txt file and use field[2] to calculate average for every years separate. My code give only total average.

data file looks like: (1. day of year: 101 and last: 1231)

> 
> Date 3700300 6701500
> 
> 
> 20000101 21.00 223.00 
> 
> 
> 20000102 20.00 218.00 
> 
> 
> . .
> 
> 
> 20001231 7.40 104.00 
> 
> 
> 20010101 6.70 104.00
> 
> 
> . .
> 
> 
> 20130101 8.37 111.63
> 
> 
> . .  
> 
>  20131231 45.00 120.98
> 
> 
> 

```
import sys

td=open("Qdata.txt","r") # open file Qdata

total=0
count=0
row1=True

for row in td :
    if (row1) :
            row1=False # row1 is for topic

    else:
            fields=row.split() 
            try:
                    total=total+float(fields[2])
                    count=count+1
            # Errors.
            except IndexError:
                    continue
            except ValueError:      
                    print("File is incorrect.")
                    sys.exit()

print("Average in 2000 was: ",total/count)

```