Skip to content

Instantly share code, notes, and snippets.

@smithjessk
Last active February 28, 2016 22:35
Show Gist options
  • Save smithjessk/584b8411f5342e1cbcf1 to your computer and use it in GitHub Desktop.
Save smithjessk/584b8411f5342e1cbcf1 to your computer and use it in GitHub Desktop.
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