Term 2 - Record Book Programs
Term 2 - Record Book Programs
school.
(i) Use different colors for each bar.
(ii) Title for x axis should be „Groups‟ and title for y axis should be „Number of
Students
(iii) Ensure the title of chart is “Group wise Students” and grid line must be shown.
Sample data: Group: I, II, III, IV and Strength: 38, 30, 45, 49
Group=['I','II','III','IV']
Strength=[38,30,45,49]
plt.xlabel('Group')
plt.ylabel('Number of students')
plt.grid(True)
plt.show()
Write a Python program to display the given Result using a BAR CHART
Maths Science SST
Amit 100 100.0 60.0
Mohan 95 100.0 57.48
Sudha 85 100.0 53.58
(i) Set the title of graph is “Result Analysis”
(ii) Display the legends.
(iii) Display the label of x axis to “Name” and y axis to “Score”
import numpy as np
Subject=['Maths','Science','SST']
Amit=[100,100.0,60.0]
Mohan=[95,100.0,57.48]
Sudha=[85,100.0,53.58]
x_axis=np.arange(len(Subject))
plt.xticks(x_axis, Subject)
plt.legend(loc=1)
plt.xlabel("Name")
plt.ylabel("Score")
plt.title("Result Analysis")
plt.show()
Write the code to draw the following line graph.
Group=['VII','VIII','IX','X']
No_Students=[40,45,35,45]
plt.bar(Group,No_Students)
plt.xlabel("Class")
plt.ylabel("Students")
plt.show()
Write a program to plot a bar chart in python to display the result of a school for five
consecutive years.
SOURCE CODE:
import matplotlib.pyplot as pl
data=[[5,25,45,20],[8,1,29,27],[9,29,27,39]]
import numpy as np
data=[[5,25,45,20],[8,1,29,27],[9,29,27,39]]
x=np.arange(4)
plt.plot(x,data[0],color='b',label='range 1')
plt.plot(x,data[1],color='g',label='range 2')
plt.plot(x,data[2],color='r',label='range 3')
plt.legend(loc='upper left')
plt.xlabel('X')
plt.xlabel('Y')
plt.show()
A survey gathers heights and weight of 50 participates and recorded the
participants age as
Ages=[40,56,46,58,79,70,67,46,32,91,92,93,47,95,69,69,56,50,30,9,29,29,0,31,21,14,18,1
6,18,76,68,69,78,81,71,91,71,01,69,78,77,54,59,59,41,51,48,49,76,10]
import numpy as np
Ages=[40,56,46,58,79,70,67,46,32,91,92,93,47,95,69,69,56,50,30,90,29,29,\
45,31,21,14,18,16,18,76,68,69,78,81,71,91,71,30,69,78,77,\
54,59,59,41,51,48,49,76,10]
plt.hist(Ages,bins=10)
plt.show()
Write a program that reads from a csv file (marks.csv stored in desired
location) in a data frame then add a column Total storing total marks in three subjects
and another column for storing average marks. Print the data frame after adding these
columns.
import pandas as pd
df=pd.read_csv('c:\\data\marks.csv',names=['Name','Marks1','Marks2','Marks3'])
print(df)
df['Total']=df['Marks1']+df['Marks2']+df['Marks3']
df['AvgMarks']=df['Total']/3
print(df)