473,385 Members | 1,730 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

making a pie chart question

3
hi, i'm new in python programming
i'm trying to write a simple program that processes a text file containing grades for a class, extracts the desired grades, count the number of grades in each grade segment and genrate a pie chart for grades,(A1) .
http://pages.cpsc.ucalgary.ca/~zongpeng/CPSC231/assignments/A3/a3.pdf

txt file:http://pages.cpsc.ucalgary.ca/~zongpeng/CPSC231/assignments/A3/grades1.txt

i was able to extract the 6th column with this code
Expand|Select|Wrap|Line Numbers
  1. infile = open('grades1.txt','r')
  2. all_lines = infile.readlines()
  3. all_lines = all_lines[1:]
  4. all_lines = all_lines[:-2]
  5.  
i need help in assigning a grade to the results
and that's what i got so far but it doesn't seem to be working

Expand|Select|Wrap|Line Numbers
  1. A+ =[10]
  2. A = [9,10)
  3. A- =[8,9)
  4. B+ =[7,8)
  5. B =[6,7)
  6. B- =[5,6)
  7. C+ =[4,5)
  8. C =[3,4)
  9. D+ =[2,3)
  10. F =[0,1)
  11.  
  12.  
  13. grades=["ABCDA"]
  14. i=0
  15. total=0
  16. while i<len(grades):
  17.     if grades[i]  =='A':
  18.         total=total+1
  19.         i=i+1
  20. print total
any help would be really appreciated
Nov 2 '09 #1
1 3001
bvdet
2,851 Expert Mod 2GB
You do not have the sixth column with your code. You have a list of all the lines in the file minus the first and last two lines. The sixth column would be saved with this code:
Expand|Select|Wrap|Line Numbers
  1. f = open("grades.txt")
  2. sixthCol = [line.split()[5] for line in f.readlines()[1:-1]]
  3. f.close()
You should store the data in a form that can be accessed for information. I would suggest a dictionary of dictionaries, but you can tabulate the information in a list of lists or tuples, whatever you are comfortable with. Here's some psuedocode:

Open file, create a file object
Read first line, save as column labels (strip and split the line)
Initialize a dictionary
Iterate on the file object (for line in fObj:)
....Assign dictionary key ID (line[0]) to a dictionary with column labels
........as keys and items (line[1:]) as values.
Close file object.


This can be accomplished with just a few lines of code. A column of grades can be summed like this:
Expand|Select|Wrap|Line Numbers
  1. >>> gradeA1 = sum([float(dd[key]['A1']) for key in dd])
  2. >>> A1
  3. 1128.0
  4. >>> 
Here's a hint to create the dictionary for each line in the file:
Expand|Select|Wrap|Line Numbers
  1. >>> listA = ['A', 'B', 'C']
  2. >>> listB = ['12', '13', '14']
  3. >>> dict(zip(listA, listB))
  4. {'A': '12', 'C': '14', 'B': '13'}
  5. >>> 
You need to find a way to convert a number grade into a letter grade. Here's where a dictionary would work well again. Assume a '9.5' is the same as a '9', and we can take the integer. Assign the intergers 0-10 to the corresponding letter grade. Then we can do this:
Expand|Select|Wrap|Line Numbers
  1. >>> grade = '7.5'
  2. >>> gradeDict[int(float(grade))]
  3. 'B+'
  4. >>> 
Good luck. Post again if you have more questions.
HTH
BV
Nov 2 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Patrick.O.Ige | last post by:
I have a code below and its a PIE & BAR CHART. The values now are all static but I want to be able to pull the values from a database. Can you guys give me some ideas to do this? Thanks ...
6
by: Hazz | last post by:
I have been asked what I thought would be a good database design, data delivery mechanism and rendering method for an org chart with as many as 100,000 people. No other design specifications. 1....
2
by: Anil | last post by:
Hello, I am using VS2005 Beta2 and I have added a Simple Line-Graph chart to a ReportViewer control. I can click on the chart and alter for example the Minimum and Maximum scale values of the...
1
by: Marcin | last post by:
Hello all! I have unusual problem with a database form. I have a few forms with charts. I`ve created a module which changes me a chart title. I send an object into the module function and then I...
5
by: Tomaz Koritnik | last post by:
Anyone knows of free or commercial pie chart control that has this features: - I need only 2D pie chart type - Can be commercial but not too expensive - Save chart to WMF or EMF - Since chart...
0
by: Gilberto Avila | last post by:
I'm currently developing a web application with ASP .NET 1.1. I'm using the bundled Crystal Reports in Visual Studio 2003 to create reports for this application. The system specification requires...
1
by: devagupt | last post by:
i have a form called get downtime data. WHen information is entered into it and the button "get downtime data" pressed , it displays the results of a query. WHen i view the query in pivot chart view...
1
by: supermanii | last post by:
Hi everybody, I have a problem in vb6 code. I would like to make a chart on excel file with vb and I can make it with this code. With oChart .SeriesCollection.NewSeries ...
2
by: DaveD170 | last post by:
Hi everybody, I'm newbie in c# and I'm having trouble in creating an excel chart. I have vector of data that my program calculated. It's in the next format: X Y 0.1 100 0.2 90...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.