daily pastebin goal
29%
SHARE
TWEET

Untitled

a guest Mar 20th, 2019 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import agate
  2. from decimal import Decimal
  3.  
  4. class RunningSum(agate.Computation):
  5.     def __init__(self, column_name):
  6.         self.column_name = column_name
  7.  
  8.     def get_computed_data_type(self, table):
  9.         return agate.Number()
  10.  
  11.     def run(self, table):
  12.         so_far = Decimal()
  13.         sums = []
  14.         for value in table.columns[self.column_name]:
  15.             so_far += value
  16.             sums.append(so_far)
  17.         return sums
  18.  
  19. # Usage
  20.  
  21. t = agate.Table.from_csv('foo.csv')
  22.  
  23. with_sum = t.compute([('name_of_sum_column', RunningSum('column_with_numbers'))])
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top