Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6219069
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T07:42:57+00:00 2026-05-24T07:42:57+00:00

I have several CSV files in this format, named n-data.csv where n is the

  • 0

I have several CSV files in this format, named n-data.csv where n is the number of threads:

elapsed,label
120,Step 01
260,Step 02
113,Step 03
100,Step 01
200,Step 02
103,Step 03

and I would like to get the average of each step per thread (or n), and plot them as grouped bar charts much like this: http://matplotlib.sourceforge.net/examples/api/barchart_demo.html

My code works fine with one file (thanks to Yet Another list csv file in Python Question):

#!/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()

However, when I run this script with create_bar.py *csv, all the data gets pushed into av (average) and idx (index), and it aggreates all the data into av and idx — which works as it should.

How do I break out av and idx so I can create group charts? I tried:

    threads = file.split('-')[0]
    for count in threads
      for row in csv.DictReader(open(file)):
      ...
        av['threads'].append(a)
        idx['threads'].append(i)

to no avail.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T07:42:58+00:00Added an answer on May 24, 2026 at 7:42 am

    Perhaps have a list of lists …

    av = []
    idx = []
    
    for file in sys.argv[1:]:
        next_av = []
        next_idx = []
    
        ...
    
        for i in sorted (result.iterkeys()):
            s = sum(int(v) for v in result[i])
            a = s/float(len(result[i]))
            next_av.append(a)
            next_idx.append(i)
        av.append(next_av)
        idx.append(next_idx)
    
    for index in range(len(av)):
        # do something with the lists av[index] and idx[index]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have several csv's that look like this: I have several large text files
I have several files about 15k each of CSV data I need to import
I have several billion rows of data in CSV files. Each row can have
Basically, I have data of several people contained in a .csv file. This spreadsheet
I have several csv files that I need to transfer over to mdb format.
I have several .csv files with similar filenames except a numeric month (i.e. 03_data.csv,
I have several large csv files with thousands of columns that I need to
I currently have a .csv file with several unlabeled columns of data, which to
I have tried to import several csv files into one file. However, the new
I have a CSV file with several entries, and each entry has 2 unix

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.