0% found this document useful (0 votes)
3 views103 pages

Info Practical (Final)

This document is a practical record for Sreehari Rajesh from United International Indian School, detailing various Python programming tasks related to Pandas, including creating series and dataframes, performing arithmetic operations, and retrieving data based on conditions. It includes a bonafide certificate, an index of programs, and multiple example programs with code and expected outputs. The practical work is submitted for the All India Senior School Certificate Practical Examination for the academic year 2024-25.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views103 pages

Info Practical (Final)

This document is a practical record for Sreehari Rajesh from United International Indian School, detailing various Python programming tasks related to Pandas, including creating series and dataframes, performing arithmetic operations, and retrieving data based on conditions. It includes a bonafide certificate, an index of programs, and multiple example programs with code and expected outputs. The practical work is submitted for the All India Senior School Certificate Practical Examination for the academic year 2024-25.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 103

INFORMATICS PRACTICES

PRACTICAL RECORD

NAME : SREEHARI RAJESH


CLASS: XII A
ROLL NO: _______
United International Indian School

Bonafide Certificate

This is to certify that this practical work is done by Sreehari Rajesh of class XII-A
in the computer lab during the academic year 2024-25

DATED: _________ _______________________________

Mrs. Shalini Shaji John

P.G.T in Informatics Practices

United International Indian School, Kuwait.

Submitted to ALL INDIA SENIOR SCHOOL CERTIFICATE PRACTICAL EXAMINATION


held in the Computer Lab at United International Indian School, Kuwait.

DATED: __________ ___________________________

External Examiner
INDEX
NAME OF THE TEACHER'S
PGM DATE PAGE
PROGRAM SIGN
NO NO

PYTHON PROGRAMS

1 PANDAS SERIES - I

2 PANDAS SERIES -II


3 PANDAS SERIES - III
4 PANDAS SERIES -IV
5 PANDAS DATA FRAME - I
6 PANDAS DATA FRAME - II
7 PANDAS DATA FRAME - III
8 PANDAS DATA FRAME - IV
9 CSV FILES I - read_csv ( )
10 CSV FILES II - to_csv ( )
11 PYPLOT I - LINE CHART
12 PYPLOT II - BAR CHART
13 PYPLOT III- HISTOGRAM - I
14 PYPLOT IV–HISTOGRAM-II

MYSQL TABLES
1 MYSQL TABLE I - TEACHER
2 MYSQL TABLE II - HOSPITAL
3 MYSQL TABLE III - SPORTS
4 MYSQL TABLE IV- LIBRARY
MYSQL TABLE V-
5 CUSTOMER & ITEM
PYTHON PROGRAMS
PYTHON PROGRAM-I
PANDAS SERIES-1

1a) To create a series from a list with values one, two, three, four, five,
six

To print the series with default index values

To print the series and give it the index values of ‘a’, ‘b’, ‘c’, ‘d’, ‘e’

PROGRAM:

import pandas as pd

l=['one','two','three','four','five','six']

s=pd.Series(l)

print(s)

OUTPUT:

1b) Write a python program to create a pandas series from a dictionary


of values given below
Dictionary ={‘a’:100, ‘b’:200, ‘c’:300, ‘d’:400, ‘e’:500}

1
PROGRAM:

import pandas as pd

dictionary={"a":100, "b":200, "c":300, "d":400,"e":500}

s=pd.Series(dictionary)

print(s)

OUTPUT:

1c) To create a Series from an array A of values [10 20 30 40 50 60 70


80 90 100] Without range function with index values
A,B,C,D,E,F,G,H,I,J

PROGRAM:
import pandas as pd
import numpy as np

A=np.array([10,20,30,40,50,60,70,80,90,100])
s=pd.Series(A,index=['A','B','C','D','E','F','G','H','I','J'])
print(s)

2
OUTPUT:

1d) Using arange function create a series using an array of values [10
20 30 40 50 60 70 80 90 100] with default index values

PROGRAM:
import pandas as pd
import numpy as np
s=pd.Series(np.arange(10,101,10))
print(s)

OUTPUT:

3
PYTHON PROGRAM-II
PANDAS SERIES-2
2) To perform basic arithmetical operation of addition, subtraction,
multiplication, division, and integer division on two series s1 and s2
with values

s1 = [10,20,30,40,50] & s2 = [2,4,6,8,10]

PROGRAM:
import pandas as pd
import numpy as np
s1=[10,20,30,40,50]
s2=[2,4,6,8,10]
s1=pd.Series(s1)
s2=pd.Series(s2)
print(s1.add(s2,fill_value=0))
print("______________")
print(s1.sub(s2,fill_value=0))
print("______________")
print(s1.mul(s2,fill_value=0))
print("______________")
print(s1.div(s2,fill_value=0))
print("______________")
print(s1//s2)

4
OUTPUT:

5
PYTHON PROGRAM – III
PANDAS SERIES-III

Create a Series from an array of 25 numbers between 10 to 60. Print


the Series. Also print the following queries.
i. Print the second element.
ii. Print the 5th element
iii. Print all the elements in the reverse order i.e., last to first
iv. Print the 10th to 20th element
v. Print the 5th to last element skipping 2 elements in between
vi. Print 20th to last element by adding 5 in each elements.
vii. Print twice of each elements
viii. Print last 5 elements.
ix. Print first 7 elements.
x. Print last 5 elements by slicing
xi. Print element number 3,7,10,15,19,24

6
PROGRAM:
import pandas as pd

import numpy as np

x = pd.Series(np.arange(10,60,2))

print (x)

OUTPUT:

7
i. Print the second element.
PROGRAM
import pandas as pd

import numpy as np

x = pd.Series(np.arange(10,60,2))

print (x.iloc[1])
OUTPUT

ii. Print the 5th element


PROGRAM
import pandas as pd

import numpy as np

x = pd.Series(np.arange(10,60,2))

print (x.iloc[4])

OUTPUT

8
iii. Print all the elements in the reverse order i.e., last to first
PROGRAM
import pandas as pd

import numpy as np

x = pd.Series(np.arange(10,60,2))

print (x[::-1])

OUTPUT

9
iv. Print the 10th to 20th element
PROGRAM
import pandas as pd

import numpy as np

x = pd.Series(np.arange(10,60,2))

print (x[9:20])

OUTPUT

10
v. Print the 5th to last element skipping 2 elements in between
PROGRAM
import pandas as pd

import numpy as np

x = pd.Series(np.arange(10,60,2))

print (x[4:-1:2])

OUTPUT

11
vi. Print 20th to last element by adding 5 in each elements.
PROGRAM
import pandas as pd

import numpy as np

x = pd.Series(np.arange(10,60,2))

y = (x[19::])

print (y+5)

OUTPUT

12
vii. Print twice of each elements
PROGRAM
import pandas as pd

import numpy as np

x = pd.Series(np.arange(10,60,2))

print (x*2)

OUTPUT

13
viii. Print last 5 elements.
PROGRAM
import pandas as pd

import numpy as np

x = pd.Series(np.arange(10,60,2))

print (x.tail(5))

OUTPUT

14
ix. Print first 7 elements.
PROGRAM
import pandas as pd

import numpy as np

x = pd.Series(np.arange(10,60,2))

print (x.head(7))

OUTPUT

x. Print last 5 elements by slicing


PROGRAM
import pandas as pd

import numpy as np

x = pd.Series(np.arange(10,60,2))

print (x[-5:])

OUTPUT

15
xi. Print element number 3,7,10,15,19,24
PROGRAM
import pandas as pd

import numpy as np

x = pd.Series(np.arange(10,60,2))

print (x[3,7,10,15,19,24])

OUTPUT

16
PYTHON PROGRAM – IV
PANDAS SERIES-IV

To retrieve MARKS in a Series S1 based on the conditions given below.


The list of marks are [45.5,67.75,89.5,33.25,90.75,70.0,29.25,95.5]
i. Display all marks with value less than or equal to 40.
PROGRAM:
import pandas as pd
import numpy as np
marks=[45.5,67.75,89.5,33.25,90.75,70.0,29.25,95.5]
S1=pd.Series(l)
print('''\ni.''')
print(S1[S1<=40],'\n')
OUTPUT:

17
ii. Display all marks with values greater than or equal to 90.
PROGRAM:
import pandas as pd
import numpy as np

marks=[45.5,67.75,89.5,33.25,90.75,70.0,29.25,95.5]
S1=pd.Series(l)
print('''\nii.''')
print(S1[S1>=90],'\n')

OUTPUT:

18
iii. Display all marks not less than 60
PROGRAM:
import pandas as pd
import numpy as np

marks=[45.5,67.75,89.5,33.25,90.75,70.0,29.25,95.5]
S1=pd.Series(l)

print('''\niii.''')
print(S1[S1>=60],'\n')
OUTPUT:

19
iv. Display all marks not above 40.
PROGRAM:
import pandas as pd
import numpy as np

marks=[45.5,67.75,89.5,33.25,90.75,70.0,29.25,95.5]
S1=pd.Series(l)

print('''\niv.''')
print(S1[S1<=40],'\n')
OUTPUT:

20
v. Display all the marks other than 70.
PROGRAM:
import pandas as pd
import numpy as np

marks=[45.5,67.75,89.5,33.25,90.75,70.0,29.25,95.5]
S1=pd.Series(l)
print('''\nv.''')
print(S1[S1!=70],'\n')

OUTPUT:

21
PYTHON PROGRAM – V
PANDAS DATAFRAME-I
Virat Rohit Samson
M1 55 88 99
M2 66 66 101
M3 31 43 68
a) Write a program to create a data frame ‘players’ using list of
dictionaries method as given above. Also
iterate the data frame by its rows to display the values in each row.

PROGRAM:
import pandas as pd
import numpy as np
players = pd.DataFrame({'Virat': pd.Series([55, 66, 31], index=['M1',
'M2', 'M3']), 'Rohit': pd.Series([88, 66, 43],
index=['M1','M2','M3']),'Samson':pd.Series([99,101,68],
index=['M1', 'M2', 'M3'])})
print("DataFrame 'players':")
print(players)
print("Values in each row:")
for index, row in players.iterrows():
print("Row",index,":")
print(row)
print()

22
OUTPUT:

23
b) Write a program to create a dataframe ‘players’ using dictionary of
series method as given above. Also iterate the dataframe by its columns
to display the values in each column.
PROGRAM:
import pandas as pd
data = {'Virat': pd.Series([55, 66, 31], index=['M1', 'M2', 'M3']),'Rohit':
pd.Series([88, 66, 43], index=['M1', 'M2', 'M3']),'Samson': pd.Series([99,
101, 68], index=['M1', 'M2', 'M3'])}
players = pd.DataFrame(data)
print("DataFrame 'players':")
print(players)
print("Values in each column:")
for col in players.columns:
print(col,":")
print(players[col])
print()

24
OUTPUT:

25
PYTHON PROGRAM – VI
PANDAS DATAFRAME-II
Write a python program to create a data frame as given below and
display all its attributes (index, columns, shape, size, axes, values,
dimensions, empty, transpose, dtypes).

RollNo Name Year Percentage


10E01 Aman 1982 98.5
12E05 Raghav 1984 86.9
10E12 Rishi 1982 76.6
12E15 Manvi 1984 80.0
10E25 Vivek 1982 87.5

PROGRAM:
import pandas as pd
import numpy as np
d=pd.DataFrame({'RollNo':pd.Series(['10E01','10E02','10E03','10E04','1
0E05']),'Name':pd.Series(['Aman','Raghay','Rishi','Manyi','Vivek']),'Year':
pd.Series([1982,1984,1982,184,1982]),'Percentage':pd.Series([98.5,86.
9,76.6,80.0,87.5])})
print('Index Values')
print(d.index)
print('\nColumn Values')
print(d.columns)
print('\nShape of Dataframe')
print(d.shape)

26
print('\nSize of Dataframe')
print(d.size)
print('\nAxes of Dataframe')
print(d.axes)
print('\nValues of Dataframe')
print(d.values)
print('\nDimensions of Dataframe')
print(d.ndim)
print('\nTo check whether dataframe is empty or not')
print(d.empty)
print('\nTo Transpose the Dataframe')
print(d.T)
print('\nTo print Datatypes of Dataframe')
print(d.dtypes)

27
OUTPUT:

28
PYTHON PROGRAM – VII

To create a Data Frame DF as shown below and perform the following


operations on it.

II. To display the first 3 rows of the Data Frame


III. To display the last 4 rows of the Data frame
IV. To add a new column Gender to the above Data frame
V. To add a new row to the above Data Frame
VI. To display the row labels and column labels of the above Data frame
VII. To display the data type of each column and dimension of the
above Data Frame
VIII. To display the total number of elements of the above Data Frame
IX. To display the column age and its maximum value from the above
Data Frame.
X. To display the column Salary and its minimum value from the above
Data Frame
XI. To remove the column Gender added in the above Data Frame
XII. To remove the 5th row of the Data Frame

29
PROGRAM:
import pandas as pd

DF = pd.DataFrame({'NO':[1,2,3,4,5],
'NAME':
['JUGAL','SHARMILA','SANDEEP','SANGEETHA','RAKESH'],'AGE':
[34,31,32,35,42],'DEPT':
['COMPUTER','HISTORY','MATHS','HISTORY','COMPUTER'],'DOJ':['1994-
01-10','1998-03-24','1996-12-12','1999-07-01','1998-027'],
'SALARY':[10000,12000,20000,15000,16000]})
print('to print first 3 rows ')
print(DF.head(3))
print('to print last 4 rows')
print(DF.tail(4))
print('to add new column Gender')
DF['GENDER']=['M','F','M','F','M']
print(DF)
print('to add new row')
DF.loc[6]=[6,’SHAJI’,40,'MATHS','1999-08-20',80000,'M']
print(DF)
print('to display the row labels and columns labels from the above
dataframe')
print(DF.index)
print(DF.columns)

30
print('To display the data type of each column and dimension of the
above Data Frame')
print(DF.dtypes)
print(DF.ndim)
print('To display the total number of elements of the above Data Frame
')
print(DF.size)
print('To display the column age and its maximum value from the above
Data Frame')
print(DF[['AGE']])
print(max(DF['AGE']))
print('To display the column Salary and its minimum value from the
above Data Frame')
print(DF[['SALARY']])
print(min(DF['SALARY']))
print('To remove the column Gender added in the above Data Frame ')
DF=DF.drop('GENDER',axis='columns')
print(DF)
print('To remove the 5th row of the Data Frame')
DF=DF.drop(4,axis='index')
print(DF)

31
OUTPUT

32
33
34
PYTHON PROGRAM – VIII
PANDAS DATAFRAME-IV
i) Create the following Data Frame Sales containing year wise sales
figures for five salespersons in INR. Use the years as column labels and
names of salespersons as row labels.

ii) Display the first 2 columns of Sales.


iii) Display the last 3 rows of Sales without using tail function.
iv) Display the sales made by all salespersons in the year 2020.
v) Display the sales made by ANN and RAJ in the year 2017 and 2018.
vi) Display the sales made by SHRUTI in 2018
vii) Update the sale made by ANKIT in 2018 to 85000
viii) Delete the data for the year 2019 from the Data Frame Sales.
ix) Delete the data for sales man JUGAL from the Data Frame Sales.
x) Change the Data Frame Sales such that it becomes its transpose.

35
PROGRAM
import pandas as pd

Sales=pd.DataFrame([[100.5,12000,20000,50000],
[150.8,18000,50000,60000],[200.9,22000,70000,70000],
[300,30000,100000,80000],[400,45000,125000,90000]],
index=['ANN','SHRUTI','RAJ','ANKIT','JUGAL'],columns=[2017,2018,
2019,2020])

print('Display the first 2 columns of Sales')


print(Sales.loc[:,2017:2018])
print('Display the last 3 rows of Sales without using tail function')
print(Sales.loc['RAJ':'JUGAL',:])
print('Display the sales made by all salespersons in the year 2020')
print(Sales.loc[:,2020])
print('Display the sales made by ANN and RAJ in the year 2017 and
2018')
print(Sales.loc[['ANN','RAJ'],2017:2018])
print('Display the sales made by SHRUTI in 2018 ')
print(Sales.loc[['SHRUTI'],[2018]])
print(Sales)
print('Update the sale made by ANKIT in 2018 to 85000 ')
Sales.loc['ANKIT',2018]=85000
print(Sales)
print('Delete the data for the year 2019 from the DataFrame Sales')
Sales=Sales.drop(2019,axis='columns')

36
print('Delete the data for sales man JUGAL from the DataFrame Sales')
Sales=Sales.drop('JUGAL',axis='index')
print('Change the DataFrame Sales such that it becomes its transpose')
print(Sales.T)

OUTPUT

37
38
39
PYTHON PROGRAM – IX
CSV FILES – I

i) To read from a CSV file EMP.csv and create a data frame


from it. Emp.csv file is having the following data EMP.csv

ii) Display the data frame from the above CSV file with
column headings as 0,1,2,3
PROGRAM
import pandas as pd

df=pd.read_csv(r"C:\Users\sreeh\OneDrive\Desktop\
Emp.csv",names = [0,1,2,3],skiprows = 1)
print(df)

40
OUTPUT

iii) Display the data frame from the above CSV file and give
columns headings as NO, NAME, DESIGNATION and PAY

PROGRAM
import pandas as pd

df=pd.read_csv(r"C:\Users\sreeh\OneDrive\Desktop\
Emp.csv",names=['NO','NAME','DESIGNATION','PAY'],skipro
ws = 1)
print(df)

41
PYTHON PROGRAM – X
CSV FILES – II
i) To create a Data Frame from the given

ii) Write a program to convert the contents of this data


frame to a csv file
iii) Convert the Data Frame to CSV file with separator# *
iv) Convert the Data Frame to CSV file with separator # and
replace NaN with NULL

PROGRAM:
import pandas as pd

data = {'DEPTNO':[10,20,30, 40, 50],'DEPTNAME': ['SALES', 'FINANCE',


'ACCOUNTS', 'HR', 'NaN'],'LOC': ['DELHI', 'NaN', 'MUMBAI', 'COCHIN',
'DELHI'], 'NOE': [50, 40, 60, 30, 65]}

df = pd.DataFrame(data)

print("Original DataFrame:")

print(df)

df.to_csv('data.csv', index=False)
42
print("Data has been written to 'data.csv'")

df.to_csv('data_sep.csv', sep='#', index=False)

print("Data has been written to 'data_sep.csv' with separator '#'")

df.to_csv('data_null.csv',sep='#',na_rep='NULL',index=False)

print("Data has been written to 'data_null.csv' with separator '#' and


NaN replaced with 'NULL'")

43
OUTPUT:

44
PYTHON PROGRAM – XI
PYPLOT-I
a) Create multiple line charts on common plot where three data
ranges are plotted on same chart. The data ranges to be plotted are
Data = [[5., 25., 45., 20.,15. ], [ 8., 13., 29., 27.,18.], [ 9., 29., 27.,
39.,22.] ]
Ensure to have the following specifications on the chart
I. Line should be red in color with width of 3 and dashed dotted line
style
II. Line should be green in color with width of 4 and dotted style
III. Line should be blue in color with width of 2 and dashed line style
IV. The legends should be LINE-I, LINE-II and LINE-III and it should be
placed in the upper left corner
V. X Axis label should be X VALUES [0,1,2,3,4]
VI. Y Axis label should be Y VALUES [DATA VALUES]
VII. Title of your chart should be MULTI RANGE LINE CHART

45
PROGRAM:
import matplotlib.pyplot as plt

data = [[5., 25., 45., 20., 15.], [8., 13., 29., 27., 18.], [9., 29., 27., 39.,
22.]]
x_values = [0, 1, 2, 3, 4]

plt.plot(x_values,data[0],color='red',linewidth=3,linestyle='-.',
label='LINE-I')
plt.plot(x_values,data[1],color='green',linewidth=4,
linestyle=':', label='LINE-II')
plt.plot(x_values,data[2],color='blue',linewidth=2,linestyle='--',
label='LINE-III')

plt.title('MULTI RANGE LINE CHART - USING MATPLOTLIB.PYPLOT')


plt.xlabel('X VALUES [0, 1, 2, 3, 4]')
plt.ylabel('Y VALUES [DATA VALUES]')
plt.legend(loc='upper left')

plt.show()

46
OUTPUT:

47
b) Write a program to plot a line chart to depict a comparison of
population in millions between India and Pakistan from 1960 to 2010
YEAR 1960 1970 1980 1990 2000 2010
INDIA 449.48 553.57 696.783 870.133 1000.4 1309.1

PAKISTAN 44.91 58.09 78.07 107.7 138.5 170.6

The line chart should have the following specifications


I. Line chart for India should be red and for Pakistan it should be
green.
II. Line Thickness for India should be 4 and for Pakistan should be 2
III. Line style for India should be Solid and for pakistan should be
dashed dot
IV. Legends INDIA and PAKISTAN should be placed in upper left
corner.
V. X Axis Label should be YEAR
VI. Y Axis Label should be POPULTION IN MILLIONS
VII. Title of the chart should be POPULATION COMPARISON B/W
INDIA AND PAKISTAN

PROGRAM:
import matplotlib.pyplot as plt
year = [1960, 1970, 1980, 1990, 2000, 2010]
india_population = [449.48, 553.57, 696.783, 870.133, 1000.4,
1309.1]
pakistan_population = [44.91,58.09,78.07, 107.7, 138.5, 170.6]
plt.plot(year,india_population,color='red', linewidth=4,
label='INDIA')

48
plt.plot(year,pakistan_population,color='green',linewidth=2,linestyle
='-.', label='PAKISTAN')
plt.title('POPULATION COMPARISON B/W INDIA AND PAKISTAN')
plt.xlabel('YEAR')
plt.ylabel('POPULATION IN MILLIONS')
plt.legend(loc='upper left')
plt.show()

49
OUTPUT:

50
PYTHON PROGRAM – X
PYPLOT-II
a) Write a Python Program to plot a bar chart from the
medals won by top four countries AUSTRALIA, ENGLAND,
INDIA and CANADA in COMMONWEALTH GAMES. MEDAL
TALLY OF COMMONWEALTH GAMES 2018
COUNTRY GOLD SILVER BRONZE TOTAL
AUSTRALI 80 59 59 198
A
ENGLAND 45 45 46 136
INDIA 26 20 20 66
CANADA 15 40 27 82

Ensure that the chart has the following specifications:


I. The color for AUSTRALIA, ENGLAND, INDIA and CANADA should be
BLUE, YELLOW, RED and GREEN
II. The width of the bars should be .15
III. X AXIS label should be MEDAL TYPE
IV. Y AXIS label should be TOP FOUR COUNTRIES TALLY
V. Title of the chart should be COMMONWEALTH GAMES – 2018
VI. Legends AUSTRALIA, ENGLAND, INDIA and CANADA should be in
the upper left corner.

PROGRAM
import matplotlib.pyplot as plt
import numpy as np

51
x=['Gold','Silver','Bronze','Total']
AUSTRALIA=[80,59,59,198]
ENGLAND=[45,45,46,136]
INDIA=[26,20,20,66]
CANADA=[15,40,27,82]
y=np.arange(0,4)
plt.bar(x,AUSTRALIA,width=0.15,color='b',label='AUSTRALIA')
plt.bar(y+0.15,ENGLAND,width=0.15,color='y',label='ENGLAND')
plt.bar(y+0.30,INDIA,width=0.15,color='r',label='INDIA')
plt.bar(y+0.45,CANADA,width=0.15,color='g',label='CANADA')
plt.xlabel('MEDAL TYPE')
plt.ylabel('TOP FOUR COUNTRIES TALLY')
plt.title('COMMON WEALTH GAMES - 2018')
plt.legend(loc='upper left')
plt.show()

OUTPUT

52
53
b) Write a Python Program to plot a horizontal bar chart for INDIA’S
MEDAL TALLY from the table given below

COUNTRY GOLD SILVER BRONZE TOTAL


AUSTRALI 80 59 59 198
A
ENGLAND 45 45 46 136
INDIA 26 20 20 66
CANADA 15 40 27 82
MEDAL TALLY OF COMMONWEALTH GAMES 2018

Ensure the following specifications


i) Color for the medals should be GOLD, SILVER, BROWN and BLACK
ii) X AXIS label should be MEDAL COUNT
iii) Y AXIS label should be MEDAL TYPE
iv) Title of the chart should be COMMONWEALTH GAMES INDIA –
2018
v) Display the chart in a grid.

PROGRAM

import matplotlib.pyplot as plt


import numpy as np

x=['Gold','Silver','Bronze','Total']
54
AUSTRALIA=[80,59,59,198]
ENGLAND=[45,45,46,136]
INDIA=[26,20,20,66]
CANADA=[15,40,27,82]
y=np.arange(0,4)
plt.barh(x,AUSTRALIA,color='b',label='AUSTRALIA')

plt.xlabel('MEDAL COUNT')
plt.ylabel('MEDAL TYPE')
plt.title('COMMON WEALTH GAMES - 2018')
plt.legend(loc='upper left')
plt.grid(True)

plt.show()

OUTPUT

55
PYTHON PROGRAM – XI
PYPLOT-III
a) Given below are the sugar levels for men and women in a city.
Compare the sugar levels among them through a histogram.
MEN= [113,85,90,150,149,88,93,115,135,80,77,82,129]
WOMEN= [67,98,89,120,133,150,84,69,89,79,120,112,100]
56
Ensure the following specifications in the chart
• Title should be Blood Sugar Analysis
• X axis label should be Sugar Range
• Y axis label should be Total Number Of patients
• Color for Men should be Red and for women should be black
• Legends MEN and WOMEN should be placed in the upper right
corner of your chart

PROGRAM

import matplotlib.pyplot as plt

MEN= [113,85,90,150,149,88,93,115,135,80,77,82,129]
WOMEN= [67,98,89,120,133,150,84,69,89,79,120,112,100]
plt.hist([MEN,WOMEN],color=['Red','Black'],label=['MEN','WOMEN'])
plt.title('Blood Sugar Analysis')
plt.xlabel('Sugar Range')
plt.ylabel('Total Number Of Patients')
plt.legend()

plt.show()

57
58
OUTPUT

b) Modify the above code to display the histogram horizontally and


to display the legend in the lower right corner.

PROGRAM

59
import matplotlib.pyplot as plt

MEN= [113,85,90,150,149,88,93,115,135,80,77,82,129]
WOMEN= [67,98,89,120,133,150,84,69,89,79,120,112,100]
plt.hist([MEN,WOMEN],color=['Red','Black'],orientation='horizontal',l
abel=['MEN','WOMEN'])
plt.title('Blood Sugar Analysis')
plt.xlabel('Sugar Range')
plt.ylabel('Total Number Of Patients')
plt.legend(loc ='lower right')

plt.show()

60
OUTPUT

PYTHON PROGRAM – XIV


PYPLOT-IV
61
a) Given the ages of 50 participants in a Chess tournament
conducted by IIT,Roorkee. Write a program to plot a histogram from
given data with 15 bins.
Data={10,11,13,13,15,16,17,18,19,21,23,23,23,24,24,25,25,25,25,25,
26,26,27,27,27,29,30,30,30,31,33,34,34,3
5,36,36,37,37,37,38,39,40,40,40,41,42,43,43} Ensure the following
specifications in the chart
 Title should be Chess Tournament
 X axis label should be Ages
 Y axis label should be Number of participants
 Outline color of the histogram should be black and bar color should
be green.

62
PROGRAM

import matplotlib.pyplot as plt


Data=[10,11,13,13,15,16,17,18,19,21,23,23,23,24,24,25,25,25,25,25,
26,26,27,27,27,29,30,30,30,31,33,34,34,35,36,36,37,37,37,38,39,40,
40,40,41,42,43,43]

plt.hist(Data,bins=15,edgecolor='black',color='green')
plt.title('Chess Tournament')
plt.xlabel('Ages')
plt.ylabel('Number of participants ')
plt.show()
OUTPUT

63
MYSQL TABLES

MY SQL - I
TABLE: - TEACHER

64
1. Create the table Teacher with the following attributes and
records.

65
2.To display all the information about the teachers of History
department whose name starts with the letter S.

3.To display the names of female teachers who are in Math


department.

4.To display the names and departments of all teachers with


their date of joining in descending order.

66
5.To increase the salary by 500 for all the teacher working in
computer department.

6.To insert a new row in the teacher table with the following
data:
[7, ’Raj’, 26, ‘computer’, ‘1995-05-13’, 20000, ‘M’]

67
7.To count the number of teachers with age greater than 23.

8.To display the different department in the teacher table.

9.To remove all the teachers who joined after 1998.

68
10.To add a new column called Address in the above table.

11.Write a command to view the structure of the above table

69
12.To change dept column to DEPARTMENT in the above table

70
WRITE OUTPUTS:
1. Select Count(Distinct Dept ) From Teacher;

2. Select Max(Age) from Teacher where Sex=’F’;

3. Select Avg(SALARY) from teacher where Sex=’M’;

71
4. Select Name, Age from Teacher Order By salary Desc;

MYSQL - II

72
TABLE: - HOSPITAL

1. Create table hospital with the following attributes and records.

73
2) To display the names of the patients in uppercase and
departments in lowercase for female patients in ENT

3) To return the second to fourth character from departments for


all male patients.

4) To list the position of character ‘a’ in the names of patients


who are aged over 50.

5) To display first four characters of department field who were


admitted before 2008

74
6) To display the length of department, pno and name of patient
in surgery department

75
7) To display month and year of admission of zarina

76
8) Round of charges to 1 decimal place for all patients admitted
in 1998 and who are aged above 50.

9) Round of charges to nearest tens for all those in cardiology


department in descending order of charges.

10) To display the first 4 characters of names in capitals and last


4 characters of departments in small letters whose date of
appointment is in JULY.

11) To display the name of month, day of month for all those
female patients in surgery department

77
WRITE OUTPUTS:
1) Select MOD(27,4), POW(-3,3);

2)SelectROUND(26.789,2),ROUND(45.34),RO
UND(285.678,-2);

3) Select MONTHNAME(DOA),DAY(DOA) from


hospital where department <> ‘ENT’ or name
like ‘%a’;

4)Select
SUBSTR(Name,2,4),INSTR(Department,’N’)
from Hospital where Sex=’F’;

78
79
MYSQL – III
TABLE: - SPORTS

1) Create table sports with the following attributes and records

80
2) To view all the records inserted in the above table.

3) To display the maximum and minimum fees for each type of


game.

4) To display the different games in the above table

5) To display the sum of fees of male students learning cricket.

81
6) To display the number of female students learning Badminton

7) To display the average fees of each gender type

8) To display games and sum of fees of each game


whose sum is greater than 100000.

82
9) To count the number of female students in either lawn tennis
or badminton;

83
10) To display the maximum, minimum and average fees game
wise where the number of students is greater than 2. (*)

11) To display the difference between maximum and minimum


fees gender wise

12) To display the total fees of students admitted in the year


2015.

WRITE OUTPUTS:
1. SELECT COUNT(DISTINCT GAME) FROM SPORTS;
84
2. SELECT GAME,SUM(FEES) FROM SPORTS GROUP BY
GAME;

3.SELECT
GENDER,MAX(FEES),MIN(FEES),COUNT(STUDENTID)
FROM SPORTS GROUP BY GENDER;

85
4. SELECT GAME, MAX(FEES),AVG(FEES)) FROM
SPORTS GROUP BY GAME HAVING COUNT(*)>2;

86
MY SQL-IV

TABLE:LIBRARY

1. Create the above table with following attributes and records

2. To display the book names in capital letters and author


names in small letters for all those books whose price is
between 400 and 600.

3. To display the first 4 characters of book names and last


four characters of author whose type is either OS and DS
and is published by Macmillan.
87
4. To extract 5th right characters onwards from the author
field.

5.To display the title, author name and length of all those books
whose price is greater than 200 and publisher name ends letter ‘i’

88
6.To display the position of ‘at’ in book name and the position
of ‘ha’ in author name for all those books not published by
‘Galgotia’

7. To display the last 4 characters of publisher in uppercase


and type of all books published by ‘Dhanpat Rai’ and whose
quantity greater than

8. To extract three characters from the right side of author name


and display the position of ‘p’ in publisher.

9. To remove the leading space from author and trailing spaces


from type of all those books who has a publisher.

89
10. To display the price after ignoring the decimal part for
those books whose purchase date is after 2010.

11. To change publisher name to ‘DC’ and price to 590.456


for all those books

90
12. To add the column ‘Location’ and ‘PhoneNo’ to the above
table.

13.To display the total costs of books that are purchased in the
year 2017.

14. To display highest and lowest priced book in each type


where maximum price greater than 450.

91
15. To display of number of books with same publisher

WRITE OUTPUTS:
1. SELECT NO, TITLE, AUTHOR FROM LIBRARY WHERE
PUBLISHER IN (‘MACMILLAN’,’GALGOTIA’) AND
TYPE LIKE ‘OS’;

2. SELECT TYPE, MAX(PRICE)FROM LIBRARY GROUP


BY TYPE;

92
3. SELECT PUBLISHER, TYPE FROM LIBRARY GROUP
BY PUBLISHER HAVING COUNT(*)>=2;(*)

4. Select UCASE(TITLE), ROUND(PRICE,2) from library


where price between 400 and 700 order by price desc;

93
MY SQL - IV
TABLES: - CUSTOMER & ITEM
TABLE – CUSTOMER

TABLE – ITEM

i) Create a database UIIS

ii) Create Table Customer with the following attributes and


records

94
iii) Create Table Item with the following attributes and
records under UIIS.

iv) To view the tables created under UIIS.

v) To display the cartesian product of the above 2 tables

95
vi) To display the equijoin query for the above 2 tables.

vii) To display all columns from both the tables eliminating the
identical column.

viii)To display the customer names and item names for all those
items whose price is above 50000 in alphabetical order of
their cities.

96
ix)To display the details of those customers who is from
DELHI and purchased PC HP.

x)To display name and City from the CUSTOMER table and
corresponding Item Name from the Item table whose price is
in the range of 30000 to 40000.

xi)To display all details of those who purchased PC of any


company in decreasing order of their price.

xii)To display all the details of item table whose customer is


from DELHI and customer name has the letter I in it.

97
Write Outputs for the Following Queries with respect to the
Original tables CUSTOMER and ITEM
xiii) Select * from Customer, Item where Customer.Itemcode =
Item.Itemcode;

xiv) Select Cname, ItemName from Customer, Item where


Customer.Itemcode = Item.Itemcode and ItemName like ‘%PC
%’;

xv)Select lower(customer.cname),left(customer.itemcode,2),
round(item.price,-2) from Customer, Item where
Customer.Itemcode=Item.Itemcode;

98
xvi) Select Item.*,Cname from Customer, Item where
Customer.Itemcode=Item.Itemcode and Price>=60000;

99

You might also like