Skip to content

Instantly share code, notes, and snippets.

@ckelner
Created February 3, 2015 17:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ckelner/962b9e52db11fc73cf68 to your computer and use it in GitHub Desktop.
Save ckelner/962b9e52db11fc73cf68 to your computer and use it in GitHub Desktop.
dinky little py script to total up aws consolidated billing csvs. Needed because I have csvs w/ roughly 17mil rows in the ~7Gb file size range.
import csv
import sys
from decimal import Decimal
csv_file = open( sys.argv[1] )
count = 0
total_line_item_cost = Decimal(0)
for row in csv.reader( csv_file ):
count += 1
# get record type (column 4)
rec_type = row[3]
if rec_type == "LineItem":
# get the 'UnBlendedCost' value (column 21)
unblended_cost = row[20]
total_line_item_cost += Decimal(unblended_cost.strip(' "'))
print "Rows processed: ", count
print "LineItem UnBlendedCost total: ", total_line_item_cost
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment