Why two for statements will not run together in python?
<p>I am trying to run a Python program to calculate the total and average charges that are contained within a CSV file. </p>

<p>I then want to calculate the total and average charge per invoice. The program calculates the total charges and average charges correctly, but the second for statement will not run. Both for statement run independently correctly.</p>

<pre><code>import csv
f = open("transport.csv", "r")
reader = csv.DictReader(f)
charges_per_inv = dict()
inv_reader = csv.DictReader(f)
inv_dict = dict()

counter = 0
inv_counter = 1

for row in reader:
    batch_num = row['Batch#']
    if batch_num not in charges_per_inv:
        charges_per_inv [batch_num] = 0.0
    charges_per_inv [batch_num] += float(row['Amount'])
    counter = counter + 1                           
    #print charges_per_inv #Just a check

dvalue = [(v) for v in charges_per_inv.values()]     
#print dvalue
total = sum(dvalue)
average = float(total)/ counter
#print counter #Just a check
print "The total charges is, ", total
print "The average charge is, ", average

a = raw_input("Enter Invoice#: ")

for i in inv_reader:
    inv_num1 = i["Invoice#"]
    if inv_num1 == a:
        if inv_num1 not in inv_dict:
            inv_dict[inv_num1] = 0.0
        inv_dict[inv_num1] += float(i['Amount'])    
        inv_counter = inv_counter + 1
        print inv_dict #Just a check

inv_amount = [(v) for v in inv_dict.values()]
#print inv_amount
inv_total = sum(inv_amount)
inv_average = float(inv_total)/ inv_counter
#print inv_counter #Just a check
print "The total charges is, ", inv_total
print "The average charge is, ", inv_average
</code></pre>

<p>Here is the output for the program.</p>

<pre><code>The total charges is,  9069.87
The average charge is,  72.55896
Enter Invoice#: 617537
The total charges is,  0
The average charge is,  0.0
</code></pre>
