author | Shantanu <shantanu@fossee.in> |
Mon, 12 Apr 2010 20:46:40 +0530 | |
changeset 46 | 34df59770550 |
parent 7 | 9794cc414498 |
child 47 | 501e3fb21e3c |
permissions | -rw-r--r-- |
6
e1fcec83e1ab
Added statistics.txt.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff
changeset
|
1 |
Hello welcome to the tutorial on statistics and dictionaries in Python. |
e1fcec83e1ab
Added statistics.txt.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff
changeset
|
2 |
|
46
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
3 |
Till now we have covered: |
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
4 |
* How to create plots. |
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
5 |
* How to read data from file and process it. |
6
e1fcec83e1ab
Added statistics.txt.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff
changeset
|
6 |
|
46
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
7 |
In this session, we will use them and some new concepts to solve a problem/exercise. |
6
e1fcec83e1ab
Added statistics.txt.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff
changeset
|
8 |
|
46
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
9 |
We have a file named sslc1.txt. |
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
10 |
It contains record of students and their performance in one of the State Secondary Board Examination. |
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
11 |
We can see the content of file by opening with any text editor. |
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
12 |
Please don't edit the data. |
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
13 |
It is arranged in a particular format. |
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
14 |
One particular line being: |
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
15 |
A;015163;JOSEPH RAJ S;083;042;47;AA;72;244;;; |
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
16 |
It has following fields: |
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
17 |
* Region Code which is 'A' |
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
18 |
* Roll Number 015163 |
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
19 |
* Name JOSEPH RAJ S |
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
20 |
* Marks of 5 subjects: |
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
21 |
** English 083 |
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
22 |
** Hindi 042 |
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
23 |
** Maths 47 |
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
24 |
** Science AA (Absent) |
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
25 |
** Social 72 |
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
26 |
* Total marks 244 |
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
27 |
* Pass/Fail Blank cause he was absent in one exam or else it will be(P/F) |
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
28 |
* Withheld Blank in this case(W) |
7
9794cc414498
Minor edits to statistics.txt
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
6
diff
changeset
|
29 |
|
46
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
30 |
So problem we are going to solve is: |
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
31 |
Draw a pie chart representing proportion of students who scored more than 90% in each region in Science. |
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
32 |
|
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
33 |
The result would be something like this: |
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
34 |
slide of result. |
6
e1fcec83e1ab
Added statistics.txt.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff
changeset
|
35 |
|
46
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
36 |
We would be using following machinery: |
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
37 |
File Reading(done already) |
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
38 |
parsing (done partly) |
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
39 |
Dictionaries (new) |
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
40 |
Arrays |
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
41 |
Plot (done already) |
6
e1fcec83e1ab
Added statistics.txt.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff
changeset
|
42 |
|
46
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
43 |
Dictionaries |
6
e1fcec83e1ab
Added statistics.txt.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff
changeset
|
44 |
|
46
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
45 |
We earlier used lists, we just created them and appended items to list. |
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
46 |
x = [1, 4, 2, 7, 6] |
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
47 |
to access the first element we use index number, and it starts from 0 so |
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
48 |
x[0] will give |
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
49 |
1 and |
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
50 |
x[3] will |
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
51 |
7 |
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
52 |
|
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
53 |
At times we don't have index to relate things. For example consider a telephone directory, we give it a name and it should return back corresponding number. List is not the best kind of data structure for such problems, and hence Python provides support for dictionaries. Dictionaries are key value pairs. Lists are indexed by integers while dictionaries are indexed by strings. For example: |
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
54 |
|
7
9794cc414498
Minor edits to statistics.txt
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
6
diff
changeset
|
55 |
In []: d = {'png' : 'image', |
9794cc414498
Minor edits to statistics.txt
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
6
diff
changeset
|
56 |
'txt' : 'text', |
9794cc414498
Minor edits to statistics.txt
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
6
diff
changeset
|
57 |
'py' : 'python'} |
46
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
58 |
d is a dictionary. The first element in the pair is called the `key' and the second is called the `value'. The key always has to be a string while the value can be of any type. |
6
e1fcec83e1ab
Added statistics.txt.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff
changeset
|
59 |
|
7
9794cc414498
Minor edits to statistics.txt
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
6
diff
changeset
|
60 |
Dictionaries are indexed using their keys as shown |
9794cc414498
Minor edits to statistics.txt
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
6
diff
changeset
|
61 |
In []: d['txt'] |
9794cc414498
Minor edits to statistics.txt
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
6
diff
changeset
|
62 |
Out[]: 'text' |
6
e1fcec83e1ab
Added statistics.txt.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff
changeset
|
63 |
|
7
9794cc414498
Minor edits to statistics.txt
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
6
diff
changeset
|
64 |
In []: d['png'] |
9794cc414498
Minor edits to statistics.txt
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
6
diff
changeset
|
65 |
Out[]: 'image' |
6
e1fcec83e1ab
Added statistics.txt.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff
changeset
|
66 |
|
7
9794cc414498
Minor edits to statistics.txt
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
6
diff
changeset
|
67 |
The dictionaries can be searched for the presence of a certain key by typing |
46
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
68 |
'py' in d |
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
69 |
True |
6
e1fcec83e1ab
Added statistics.txt.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff
changeset
|
70 |
|
46
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
71 |
'jpg' in d |
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
72 |
False |
7
9794cc414498
Minor edits to statistics.txt
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
6
diff
changeset
|
73 |
Please note the values cannot be searched in a dictionaries. |
6
e1fcec83e1ab
Added statistics.txt.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff
changeset
|
74 |
|
46
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
75 |
d.keys() |
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
76 |
['py', 'txt', 'png'] |
7
9794cc414498
Minor edits to statistics.txt
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
6
diff
changeset
|
77 |
is used to obtain the list of all keys in a dictionary |
6
e1fcec83e1ab
Added statistics.txt.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff
changeset
|
78 |
|
46
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
79 |
d.values() |
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
80 |
['python', 'text', 'image'] |
7
9794cc414498
Minor edits to statistics.txt
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
6
diff
changeset
|
81 |
is used to obtain the list of all values in a dictionary |
9794cc414498
Minor edits to statistics.txt
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
6
diff
changeset
|
82 |
|
46
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
83 |
d |
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
84 |
|
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
85 |
Please observe that dictionaries do not preserve the order in which the items were entered. The order of the elements in a dictionary should not be relied upon. |
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
86 |
|
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
87 |
------------------------------------------------------------------------------------------------------------------ |
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
88 |
|
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
89 |
Parsing and string processing |
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
90 |
|
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
91 |
As we saw previously we will be dealing with lines with such content |
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
92 |
A;015162;JENIL T P;081;060;77;41;74;333;P;; |
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
93 |
so ';' is delimiter we have to look for. |
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
94 |
We will create one string variable to see how can we process it get the desired output. |
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
95 |
|
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
96 |
line = 'A;015162;JENIL T P;081;060;77;41;74;333;P;;' |
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
97 |
a = line.split(';') |
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
98 |
we have used split earlier to split on empty spaces. |
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
99 |
a |
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
100 |
|
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
101 |
is list with all elements separated. |
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
102 |
a[0] is the region we want. |
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
103 |
and a[6] will give us the science marks of a particular region. |
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
104 |
So we create a dictionary of all the regions with number of students having more then 90 marks. |
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
105 |
Something like |
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
106 |
d = {'A': 729, 'C': 764, 'B': 1120,'E': 414, 'D': 603, 'F': 500} |
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
107 |
|
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
108 |
------------------------------------------------------------------------------------------------------------------ |
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
109 |
|
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
110 |
code |
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
111 |
|
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
112 |
We first create an empty dictionary |
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
113 |
|
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
114 |
science = {} |
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
115 |
now we read the record data one by one |
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
116 |
|
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
117 |
for record in open('sslc1.txt'): |
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
118 |
|
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
119 |
we split the record on ';' and store the list in 'fields' |
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
120 |
fields = record.split(';') |
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
121 |
|
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
122 |
now we strip this string for leading and trailing white spaces |
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
123 |
region_code = fields[0].strip() |
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
124 |
|
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
125 |
now we check if the region code is always there in dictionary by writing 'if' statement |
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
126 |
if region_code not in science: |
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
127 |
when this statement is true, we add new entry to dictionary with |
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
128 |
science[region_code] = 0 |
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
129 |
|
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
130 |
we again strip(ing is good) the string |
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
131 |
score_str = fields[6].strip() |
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
132 |
|
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
133 |
we check if student was not absent |
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
134 |
if score_str != 'AA': |
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
135 |
then we check if his marks are above 90 or not |
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
136 |
if int(score_str) > 90: |
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
137 |
science[region_code] += 1 |
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
138 |
|
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
139 |
Hit return twice |
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
140 |
|
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
141 |
by end of this loop we will have our desired output in the dictionary 'science' |
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
142 |
we can check the values by |
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
143 |
science |
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
144 |
|
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
145 |
now to create a pie chart we use |
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
146 |
|
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
147 |
pie(science.values(),labels = science.keys()) |
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
148 |
title('Students scoring 90% and above in science by region') |
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
149 |
savefig('science.png') |
34df59770550
Added script for sslc.txt file and presentation.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
150 |