title: Python list of list from CSV files to create grouped bar chart
body: <p>I have several CSV files in this format, named <code>n-data.csv</code> where <code>n</code> is the number of threads:</p>
  
  <pre><code>elapsed,label
  120,Step 01
  260,Step 02
  113,Step 03
  100,Step 01
  200,Step 02
  103,Step 03
  </code></pre>
  
  <p>and I would like to get the average of each step per thread (or <code>n</code>), and plot them as grouped bar charts much like this: <a href="http://matplotlib.sourceforge.net/examples/api/barchart_demo.html" rel="nofollow noreferrer">http://matplotlib.sourceforge.net/examples/api/barchart_demo.html</a></p>
  
  <p>My code works fine with one file (thanks to <a href="https://stackoverflow.com/questions/6851842/yet-another-list-csv-file-in-python-question">Yet Another list csv file in Python Question</a>):</p>
  
  <pre><code>#!/usr/bin/env python
  
  import csv
  import sys
  
  import pylab as p
  
  fig = p.figure()
  ax = fig.add_subplot(1,1,1)
  
  result = dict()
  av = []
  idx = []
  for file in sys.argv[1:]:
    for row in csv.DictReader(open(file)):
      label = row['label']
      elapsed = row['elapsed']
      if label in result:
        result[label].append(elapsed)
      else:
        result[label] = [elapsed]    
    for i in sorted (result.iterkeys()):
      s = sum(int(v) for v in result[i])
      a = s/float(len(result[i]))
      av.append(a)
      idx.append(i)
  
    y = av
    N = len(y)
    ind = range(N)
    ax.bar(ind, y, facecolor='#56A5EC',
            align='center',label='1 Thread') 
    ax.set_ylabel('Average Response Time')
    ax.set_title('Counts, by group',fontstyle='italic')
    ax.legend()
    ax.set_xticks(ind)
    ax.grid(color='#000000', linestyle=':', linewidth=1)
    group_labels = idx
    ax.set_xticklabels(group_labels)
    fig.autofmt_xdate()  
    p.grid(True) 
    p.show()
  </code></pre>
  
  <p>However, when I run this script with <code>create_bar.py *csv</code>, all the data gets pushed into <code>av</code> (average) and <code>idx</code> (index), and it aggreates all the data into av and idx -- which works as it should. </p>
  
  <p>How do I break out <code>av</code> and <code>idx</code> so I can create group charts? I tried:</p>
  
  <pre><code>    threads = file.split('-')[0]
      for count in threads
        for row in csv.DictReader(open(file)):
        ...
          av['threads'].append(a)
          idx['threads'].append(i)
  </code></pre>
  
  <p>to no avail. </p>