Python - How can I find difference between two rows of same column using loop in CSV file?
import csv

# Files to load (Remember to change these)
file_to_load = "raw_data/budget_data_2.csv"


# Read the csv and convert it into a list of dictionaries
with open(file_to_load) as revenue_data:
    reader = csv.reader(revenue_data)

    # use of next to skip first title row in csv file
    next(reader) 
    revenue = []
    date = []
    rev_change = []

    # in this loop I did sum of column 1 which is revenue in csv file and counted total months which is column 0 
    for row in reader:

        revenue.append(float(row[1]))
        date.append(row[0])

    print("Financial Analysis")
    print("-----------------------------------")
    print("Total Months:", len(date))
    print("Total Revenue: $", sum(revenue))


    #in this loop I did total of difference between all row of column "Revenue" and found total revnue change. Also found out max revenue change and min revenue change. 
    for i in range(1,len(revenue)):
        rev_change.append(revenue[i] - revenue[i-1])   
        avg_rev_change = sum(rev_change)/len(rev_change)

        max_rev_change = max(rev_change)

        min_rev_change = min(rev_change)

        max_rev_change_date = str(date[rev_change.index(max(rev_change))])
        min_rev_change_date = str(date[rev_change.index(min(rev_change))])


    print("Avereage Revenue Change: $", round(avg_rev_change))
    print("Greatest Increase in Revenue:", max_rev_change_date,"($", max_rev_change,")")
    print("Greatest Decrease in Revenue:", min_rev_change_date,"($", min_rev_change,")")



Output I got


Financial Analysis
-----------------------------------
Total Months: 86
Total Revenue: $ 36973911.0
Avereage Revenue Change: $ -5955
Greatest Increase in Revenue: Jun-2014 ($ 1645140.0 )
Greatest Decrease in Revenue: May-2014 ($ -1947745.0 )
Date   Revenue
9-Jan   $943,690.00 
9-Feb   $1,062,565.00 
9-Mar   $210,079.00 
9-Apr   -$735,286.00
9-May   $842,933.00 
9-Jun   $358,691.00 
9-Jul   $914,953.00 
9-Aug   $723,427.00 
9-Sep   -$837,468.00
9-Oct   -$146,929.00
9-Nov   $831,730.00 
9-Dec   $917,752.00 
10-Jan  $800,038.00 
10-Feb  $1,117,103.00 
10-Mar  $181,220.00 
10-Apr  $120,968.00 
10-May  $844,012.00 
10-Jun  $307,468.00 
10-Jul  $502,341.00 

# This is what I did so far...

# Dependencies
import csv

# Files to load (Remember to change these)
file_to_load = "raw_data/budget_data_2.csv"


totalrev = 0
count = 0

# Read the csv and convert it into a list of dictionaries
with open(file_to_load) as revenue_data:
    reader = csv.reader(revenue_data)

    next(reader)  



    for row in reader:

        count += 1
        revenue = float(row[1])     
        totalrev += revenue

    for i in range(1,revenue):
         revenue_change = (revenue[i+1] - revenue[i])

avg_rev_change = sum(revenue_change)/count

print("avg rev change: ", avg_rev_change)         

print ("budget_data_1.csv")
print ("---------------------------------")
print ("Total Months: ", count)
print ("Total Revenue:", totalrev)






I have above data in CSV file. I am having problem in finding revenue change, which is Revenue of row 1 - row 0 , row 2 - row 1 and so on... finally, I want sum of total revenue change. I tried with loop but I guess there is some silly mistake. Please suggest me codes so I can compare my mistake. I am new to python and coding.