Statistical calculation of USGS discharge data in Python

Dr. Huidae Cho

1   USGS discharge data

USGS discharge data

usgs_discharge_data.txt

2   Python code

data_path = r"C:\tmp\usgs_discharge_data.txt"
f = open(data_path)
skip_lines = 2
#line_count = 0
sum_disch = 0
sum_height = 0
count = 0
for line in f:
    # if line starts with a hash, skip this line
    if line.startswith("#"):
        continue
    
    line_count = line_count + 1
    if line_count <= skip_lines:
        continue
    cols = line.split("\t")
    disch = float(cols[4])
    height = float(cols[6])
    sum_disch = sum_disch + disch
    sum_height = sum_height + height
    count = count + 1
f.close()

print("Average discharge:", round(sum_disch / count, 2), "cubic feet per second")
print("Average gage height:", round(sum_height / count, 2), "feet")