title: Read csv file, sum particular column, return values
body: <p>So I have this CSV file with values as follows:</p>
  
  <pre><code>Destination Address  Count   Device Action
  10.0.0.1             5       accept
  10.0.0.2             4       deny
  10.0.0.3             6       accept
  10.0.0.2             8       accept
  10.0.0.3             6       deny
  10.0.0.1             2       accept
  </code></pre>
  
  <p>and so on.(there are also other columns in the csv file which i have omitted) </p>
  
  <p>I have written the following code to sum up the counts of each unique address for which the action is accept and return the [IP, sum] values:</p>
  
  <pre><code>with open(r'C:\Users\Traffic to blacklisted IP.csv') as oublip:
      oublip_list = list(csv.DictReader(oublip))    
  action=[column['Device Action'] for column in oublip_list]
  daddr1 = set(b['Destination Address'] for b in oublip_list)
  daddrl1 = [column['Destination Address'] for column in oublip_list]
  sumcount1 = [int(column['Sum']) for column in oublip_list]
  daddr1o = []
  for act in action:
      if act=='accept':
          for daddr in daddr1:
              sum=0
              for index, c in enumerate(daddrl1):
                  if c==daddr:
                      sum=sum+sumcount1[index]
              daddr1o.append([daddr, sum])
  daddr2o = [list(t) for t in set(map(tuple, daddr1o))]
  daddr2o.sort(key=lambda x: (x[1]), reverse=True)
  print(daddr2o)
  </code></pre>
  
  <p>Is there a better way of doing this?</p>