Info Practical (Final)
Info Practical (Final)
PRACTICAL RECORD
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
External Examiner
INDEX
NAME OF THE TEACHER'S
PGM DATE PAGE
PROGRAM SIGN
NO NO
PYTHON PROGRAMS
1 PANDAS SERIES - I
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 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:
1
PROGRAM:
import pandas as pd
s=pd.Series(dictionary)
print(s)
OUTPUT:
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
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
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
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
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
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).
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
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.
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])
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
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
PROGRAM:
import pandas as pd
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_null.csv',sep='#',na_rep='NULL',index=False)
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.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
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
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
PROGRAM
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
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
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
62
PROGRAM
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.
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.
68
10.To add a new column called Address in 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;
71
4. Select Name, Age from Teacher Order By salary Desc;
MYSQL - II
72
TABLE: - HOSPITAL
73
2) To display the names of the patients in uppercase and
departments in lowercase for female patients in ENT
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.
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);
4)Select
SUBSTR(Name,2,4),INSTR(Department,’N’)
from Hospital where Sex=’F’;
78
79
MYSQL – III
TABLE: - SPORTS
80
2) To view all the records inserted in the above table.
81
6) To display the number of female students learning Badminton
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. (*)
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
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’
89
10. To display the price after ignoring the decimal part for
those books whose purchase date is after 2010.
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.
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’;
92
3. SELECT PUBLISHER, TYPE FROM LIBRARY GROUP
BY PUBLISHER HAVING COUNT(*)>=2;(*)
93
MY SQL - IV
TABLES: - CUSTOMER & ITEM
TABLE – CUSTOMER
TABLE – ITEM
94
iii) Create Table Item with the following attributes and
records under UIIS.
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.
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;
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