Last active
February 28, 2016 22:35
-
-
Save smithjessk/584b8411f5342e1cbcf1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import csv | |
def is_first_of_month(row): | |
date_string = row[0] | |
return row[0].split('-')[2] == '01' | |
def handle_row(row): | |
if is_first_of_month(row): | |
open_price, close_price = float(row[1]), float(row[4]) | |
diff = close_price - open_price | |
day_changes.append(diff / open_price) | |
day_changes = [] | |
with open('table.csv') as csvfile: | |
reader = csv.reader(csvfile) | |
next(reader, None) | |
for row in reader: | |
handle_row(row) | |
average_change = sum(day_changes) / len(day_changes) | |
print("Average Day Change (percent): " + str(average_change * 100)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment