I need help calculating each dict of dict date values to percentage.
raw_data = [{'name':'AB', 'date':datetime.date(2012, 10, 2), 'price': 23.80}, {'name':'AB', 'date':datetime.date(2012, 10, 3), 'price': 23.72}]
i have formarted above dictionary to below format using collection.
import collections
res = collections.defaultdict(dict)
for row in raw_data:
  row_col = res[row['name']]
  row_col[row['date']] = row['price']
  {'AB': {datetime.date(2012, 10, 2): 23.80,
  datetime.date(2012, 10, 3): 23.72,
  datetime.date(2012, 10, 4): 25.90,
  datetime.date(2012, 10, 5): 29.95}
Now i need to calculate above data into below format.
Calculation formula :
last price will dividend for all the top values
   Date                               Price   Percentage 
   datetime.date(2012, 10, 5)         29.95      26%     
   datetime.date(2012, 10, 4)         25.90      9%        
   datetime.date(2012, 10, 3)         23.72      0%      
   datetime.date(2012, 10, 2)         23.80      0       
calculation goes like this
(23.72/23.80-1) * 100 = 0% 
(25.90/23.80-1) * 100 = 9% 
(29.95/23.80-1) * 100 = 26%
Any help really appreciate it.
 
     
     
    