title: Counting book inventory by user
body: <p>There is a table which contains data from 2014.The structure is as follows:
  Each user can issue different number of book category.</p>
  
  <pre><code>User-id|Book-Category
  1      |Thrill        
  2      |Thrill       
  3      |Mystery       
  3      |Mystery       
  </code></pre>
  
  <p>The requirement is to find for each user,each type of book category issued.This data is already there in csv files but it is year wise available.
  I have to add all those values.
  eg:</p>
  
  <pre><code>data for 2014
  u-id|book|count
  1   |b1  |2  
  1   |b2  |4
  ...  ...  ...
  
  data for 2015
  u-id|book|count
  1   |b1  |21
  2   |b3  |12  
  //like the above format,available till 2018.(user1 with book b1 should have a count of 23
  </code></pre>
  
  <p>Now,I wrote a python script in which I just made a dictionary and iterated each row,if the key(u-id+book-category) was present,added the values of <strong>count</strong> otherwise,inserted key-value pair in that dictionary,did this for every year wise file in that script,since some files have size>1.5GB,the script kept on running for 7/8 hours,had to stop it.</p>
  
  <p>Code:</p>
  
  <pre><code>    import requests
      import csv
      import pandas as pd
  
      Dict = {}
  
      with open('data_2012.csv') as csvfile:
          reader = csv.DictReader(csvfile)
          for row in reader:
              if row['a']+row['b'] not in Dict:
                  Dict[row['a']+row['b']] = row['c']
  ##like this,iterating over the year wise files and finally writing the data to a different file.'a' and 'b' are mentioned at the first line of the data files for an easy access.
  </code></pre>
  
  <p>Is there any way with which we can achieve this functionality more elegantly in python or write a Map-Reduce job?</p>