Informatics Practicals 12th (Personal)
Informatics Practicals 12th (Personal)
BONAFIDE CERTIFICATE
This is to certify that the practical record has been
successfully completed and executed by
Ayyub Moideen
Student of class XII- B
Under the guidance and supervision of the informatics practices
teacher
Mr.Shameer
2|Page
DECLARATION
I, AYYUB MOIDEEN student of India
International School studying in class XII-B
solemnly declare that I have completed my
practical records under the supervision of
Informatics teacher
Mr.Shameer
This practical work is submitted in partial
fulfillment for CBSE
This information incorporated in this practical is
original and genuine.
I would also thank my parents and friends who
have helped me to complete my practicals
within due time
Ayyub Moideen
Class XII B
3|Page
INDEX
SLNO PROGRAM NAME Pg NO
I P
Y
T
H
O
N
P
R
O
G
R
A
M
S
1 P
A
N
D
A
S
E
R
I
E
S
F
4|Page
R
O
M
D
I
C
T
I
O
N
A
R
Y
V
A
L
U
E
S
A
N
D
A
N
N
D
A
R
R
A
Y
2 T
5|Page
O
P
R
I
N
T
E
L
E
M
E
N
T
S
A
B
O
V
E
7
5
P
E
R
C
E
N
T
I
L
E
3 Q
6|Page
U
A
R
T
E
R
L
Y
S
A
L
E
S
4 E
C
O
M
M
E
R
C
E
D
A
T
A
&
G
E
N
E
R
7|Page
A
T
I
V
E
5 E
X
A
M
I
N
A
T
I
O
N
R
E
S
U
L
T
6 F
I
L
T
E
R
O
U
T
D
8|Page
U
P
L
I
C
A
T
E
R
O
W
7 S
U
M
O
R
L
O
W
E
S
T
M
E
A
N
O
F
T
H
E
C
9|Page
O
L
U
M
N
8 T
H
R
E
E
L
A
R
G
E
S
T
V
A
L
U
E
I
N
D
A
T
A
F
R
A
M
10 | P a g e
E
9 S
U
B
T
R
A
C
T
T
H
E
M
E
A
N
O
F
A
R
O
W
I
N
D
F
1 R
0 E
P
L
A
C
11 | P a g e
E
A
L
L
N
E
G
A
T
I
V
E
I
N
D
A
T
A
F
R
A
M
E
W
I
T
H
0
1 R
1 E
P
L
12 | P a g e
A
C
E
A
L
L
M
I
S
S
I
N
G
V
A
L
U
E
S
I
N
D
A
T
A
F
R
A
M
E
W
I
T
13 | P a g e
H
9
9
9
1 I
2 M
P
O
R
T
I
N
G
A
N
D
E
X
P
O
R
T
I
N
G
B
E
T
W
E
E
N
14 | P a g e
P
A
N
D
A
S
A
N
D
C
S
V
1 I
3 M
P
O
R
T
I
N
G
A
N
D
E
X
P
O
R
T
I
N
15 | P a g e
G
B
E
T
W
E
E
N
P
A
N
D
A
S
A
N
D
M
Y
S
Q
L
1 S
4 C
H
O
O
L
R
E
S
U
16 | P a g e
L
T
D
A
T
A
1 P
5 L
O
T
A
P
P
R
O
P
R
I
A
T
E
C
H
A
R
T
S
W
I
T
H
T
17 | P a g e
I
T
L
E
&
L
E
G
E
N
D
S
1 A
6 G
G
R
E
G
A
T
E
A
N
D
S
U
M
M
A
R
I
Z
18 | P a g e
I
N
G
D
A
T
A
O
F
O
U
R
I
N
T
E
R
E
S
T
1 W
7 E
I
G
H
T
M
E
A
S
U
R
19 | P a g e
E
M
E
N
T
S
O
F
F
R
E
N
C
H
F
R
I
E
S
1 L
8 I
N
E
C
H
A
R
T
&
B
A
R
20 | P a g e
C
H
A
R
T
D
E
P
I
C
T
I
N
G
P
R
I
C
E
O
F
A
P
P
S
1 B
9 A
R
C
H
A
R
21 | P a g e
T
D
E
P
I
C
T
I
N
G
D
I
S
T
R
I
B
U
T
I
O
N
O
F
R
A
I
N
F
A
L
L
22 | P a g e
II MYSQL
PROGRAMS
1 STUDENT TABLE
2 CUSTOMER TABLE
3 FINANCE TABLE
23 | P a g e
PYTHON
PROGRAMS
24 | P a g e
25 | P a g e
PYTHON PROGRAMS
Program-1
Q Create a pandas series from dictionary of values and an
ndarray
Source code:
import pandas as pd
import numpy as np
s=pd.Series(np.array([1,3,4,7,8,8,9]))
print(s)
dictionary={'A':10,'B':20,'c':30}
series=pd.Series(dictionary)
print(series)
print(s)
Output:
import pandas as pd
26 | P a g e
import numpy as np
s=pd.Series(np.array([1,3,4,7,8,8,9]))
print(s)
dictionary={'A':10,'B':20,'c':30}
series=pd.Series(dictionary)
print(series)
Program-2
Q2 Given a Series, print all the elements that are above
the 75th percentile
Source code:
import pandas as pd
import numpy as np
s=pd.Series(np.array([1,3,4,7,8,8,9]))
print(s)
res=s.quantile(q=0.75)
print()
print(res)
print()
27 | P a g e
print(s[s>res])
Output
0 1
1 3
2 4
3 7
4 8
5 8
6 9
dtype: int64
8.0
6 9
dtype: int64Output:
28 | P a g e
Program-3
Q3 Create a Dataframe quarterly sales where each row
contains the item category,item name, and expenditure.
Group the rows by category
Source code
import pandas as pd
dic={'itemcat':['car','AC','Aircoller','washing machine'],
'itemname':['Ford','Hitachi','Symphony','LG'],
'expenditure':[7000000,50000,12000,14000]}
quartsales=pd.DataFrame(dic)
print(quartsales)
qs=quartsales.groupby('itemcat')
print(qs['itemcat','expenditure'].sum())
Output
itemcat itemname expenditure
29 | P a g e
0 car Ford 7000000
1 AC Hitachi 50000
expenditure
itemcat
AC 50000
Aircoller 12000
car 7000000
30 | P a g e
Program-4
Q4 Create a dataframe based on ecommerce data and
generate descriptive statistics(mean,mode,quartile and
variance)
Source code
import pandas as pd
sales={'invoiceno':[1001,1002,1003,1004,1005,1006,1007],
'Productname':['LED','AC','Deodrant','jeans','Books','Shoes','jacket'],
'Quantity':[2,1,2,1,2,1,1],
'price':[6500,5500,500,2500,950,3000,2200]}
df=pd.DataFrame(sales)
print(df['price'].describe().round(2))
Output
count 7.00
mean 3021.43
std 2230.07
31 | P a g e
min 500.00
25% 1575.00
50% 2500.00
75% 4250.00
max 6500.00
Program-5
Q5 Create a data frame for examination result and
display row labels,columns label data types of each
column and the dimensions
Source code
import pandas as pd
dic={'class':['I','II','III','IV','V','VI','VII','VIII','IX','X','XI','XII'],
'pass percentage':[100,100,100,100,100,100,100,100,100,98.6,100,99]}
result=pd.DataFrame(dic)
print (result)
print(result.dtypes)
print(result.shape)
Output
class pass percentage
0 I 100.0
32 | P a g e
1 II 100.0
2 III 100.0
3 IV 100.0
4 V 100.0
5 VI 100.0
6 VII 100.0
7 VIII 100.0
8 IX 100.0
9 X 98.6
10 XI 100.0
11 XII 99.0
class object
dtype: object
(12, 2)
33 | P a g e
Program-6
Q6 Filter out row based on different criteria such as
duplicate rows
Source code:
import pandas as pd
dic={'Name':['Rohit','Mohit','Deepak','Rohit','Deepak','Sohit','Geeta'],
'MarksinIP':[85,45,92,85,92,96,84]}
marks=pd.DataFrame(dic)
duplicateRow=marks[marks.duplicated(keep=False)]
print(duplicateRow)
Output:
Name MarksinIP
0 Rohit 85
2 Deepak 92
3 Rohit 85
34 | P a g e
4 Deepak 92
Program 7
Q7 Find the sum of each column, or find the column with
lowest mean
Source code
import pandas as pd
Profit={'TCS':{'Qtr1':2500,'Qtr2':2000,'Qtr3':3000,'Qtr4':2000},
'WIPRO':{'Qtr1':2800,'Qtr2':2400,'Qtr3':3600,'Qtr4':2400},
'L&T':{'Qtr1':2100,'Qtr2':5700,'Qtr3':35000,'Qtr4':2100}}
df=pd.DataFrame(Profit)
print(df)
print()
print(df.sum(axis=0))
print()
35 | P a g e
print(df.mean(axis=0))
print()
df.mean(axis=0).idxmin()
Output:
TCS WIPRO L&T
TCS 9500
WIPRO 11200
L&T 44900
dtype: int64
TCS 2375.0
WIPRO 2800.0
36 | P a g e
L&T 11225.0
dtype: float64
TCS
Program-8
Q8 Locate the three largest value in dataframe
Source code
import pandas as pd
dic={'Name':['Rohit','Mohit','Deepak','Anil','Pankaj','Sohit','Geeta'],
'MarksinIP':[85,45,92,85,98,96,84]}
marks=pd.DataFrame(dic)
print(marks.nlargest(3,['MarksinIP']))
Output
Name MarksinIP
4 Pankaj 98
5 Sohit 96
2 Deepak 92
37 | P a g e
Program-9
Q9Subtract the mean of a row from element of the row
in Dataframe
Source Code
import pandas as pd
Profit={'TCS':{'Qtr1':2500,'Qtr2':2000,'Qtr3':3000,'Qtr4':2000},
'WIPRO':{'Qtr1':2800,'Qtr2':2400,'Qtr3':3600,'Qtr4':2400},
'L&T':{'Qtr1':2100,'Qtr2':5700,'Qtr3':35000,'Qtr4':2100}}
df=pd.DataFrame(Profit)
print(df)
print()
print(df.mean(axis=1))
print()
print('Dataframe after Subtracting mean value of each row from each element of
the row is :::')
38 | P a g e
print(df.sub(df.mean(axis=1),axis=0))
Output
TCS WIPRO L&T
Qtr1 2466.666667
Qtr2 3366.666667
Qtr3 13866.666667
Qtr4 2166.666667
dtype: float64
Dataframe after Subtracting mean value of each row from each element of the
row is :::
39 | P a g e
Program-10
Q10 Replace all negative in dataframe with a 0
import pandas as pd
dic={'Data':[-5,-2,5,8,9,-6],
'Data':[2,4,10,15,-5,-8]}
df=pd.DataFrame(dic)
print(df)
print()
df[df<0]=0
print(df)
Output
Data
0 2
1 4
2 10
40 | P a g e
3 15
4 -5
5 -8
Data
0 2
1 4
2 10
3 15
4 0
5 0
41 | P a g e
Program-11
import numpy as np
empdata={'emp':[101,102,103,104,105,106],
'ename':['Sachin','Vinod','Lakhbir',np.nan,'devinder','Umaselvi'],
'Doj':['12-01-2012','15-01-2012','05-09-2007','17-01-2012',np.nan,'16-01-
2012']}
df=pd.DataFrame(empdata)
print(df)
df=df.fillna({'ename':999,'Doj':999})
print()
print(df)
Output
42 | P a g e
emp ename Doj
43 | P a g e
Program-12
Q12 Importing and exporting data between pandas and
csv file.
Importing:
Source Code:
import pandas as pd
df1=pd.read_csv(r'D:\empl.csv')
print(df1)
Output:
Exporting:
import pandas as pd
44 | P a g e
{'Name' : 'Vinod', 'Surname' : 'Varma'}]
df1= pd.DataFrame(df)
df1.to_csv(r'D:\DataFrame1.csv')
print(df1)
Output:
45 | P a g e
Program-13
Q13 Importing and exporting data between pandas and
Mysql database.
46 | P a g e
Exporting data from Data Frame from Mysql
47 | P a g e
48 | P a g e
Program-14
Q14. Given the school result data, analyse the
performance of the student on different parameters, e.g
subject wise or class wise
Source code:
import matplotlib.pyplot as plt
Subject=['Physics','Chemistry','hindi','Biology','ComputerSc']
Percentage=[85,78,65,90,100]
plt.bar(Subject,Percentage,align='center',color='green')
plt.xlabel('SUBJECTS NAME')
plt.ylabel('PASS PERCENTAGE')
plt.show()
Output:
49 | P a g e
Program-15
Q15 For the dataframes created above, analyse and plot
appropriate charts with title and legend
Source Code:
import matplotlib.pyplot as plt
import numpy as np
s=['1st','2nd','3rd']
per_sc=[95,89,77]
per_com=[90,93,75]
per_hum=[97,92,77]
x=np.arange(len(s))
plt.bar(x,per_sc,label='Science',width=0.25,color='green')
plt.bar(x+0.25,per_com,label='commerce',width=0.25,color='red')
plt.bar(x+0.50,per_hum,label='humanities',width=0.25,color='gold')
plt.xticks(x,s)
plt.xlabel('Position')
plt.ylabel('Percentage')
plt.legend()
plt.show()
50 | P a g e
Output:
51 | P a g e
Program-16
Q 16.To take data of our interest from an open source,
aggregate and summarize it. Then plot functions of the
matplotlib.
Source Code:
52 | P a g e
Output:
53 | P a g e
Program- 17
Q17 Questions given below are based on the following
data, weight measurements for 16 small order of French
fries(in grams).
a) Create a simple histogram from the above data
b) Create a horizontal histogram from the above data
c) Create a step type of histogram from the above data
d) Create a cumulative histogram from the above data
Source code:
import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns
sns.set()
weight=[78,72,69,81,63,67,65,75,
79,74,71,83,71,79,80,69]
plt.hist(weight,bins=[60,70,80,90],edgecolor='black',color='red',width=3)
plt.show()
print()
plt.hist(weight,bins=[60,70,80,90],edgecolor='black',color='yellow',orient
ation='horizontal')
plt.show()
print()
plt.hist(weight,bins=[60,70,80,90],edgecolor='black',color='green',histtyp
e='step')
plt.show()
print()
plt.hist(weight,bins=[60,70,80,90],edgecolor='black',color='blue',width=3,
cumulative=True)
plt.show()
print(),
array= np.linspace(60,85,16,dtype='int32')
54 | P a g e
print(array)
print()
plt.hist([weight,array],bins=[60,70,80,90],edgecolor='black',color=['red',
'blue'],width=3)
plt.show()
print()
plt.hist([weight,array],bins=[60,70,80,90],edgecolor='black',color=['green
','yellow'],cumulative=True)
plt.show()
print()
plt.hist([weight,array],bins=[60,70,80,90],edgecolor='black',color=['black
','yellow'],orientation='horizontal')
plt.show()
print()
Output:
55 | P a g e
56 | P a g e
57 | P a g e
Program- 18
Q18.Create a line chart depicting the price of the apps
Source code:
import pandas as pd
import numpy as np
df1=pd.DataFrame({'APPNAME':['AngryBirds','TeamTitans','Marvel
Comics','ColourMe','PUBG','CraxyTaxi','Instagram','WhatsApp','SnapChat'],
'App Price':[75,120,190,245,550,55,175,75,140],
'Total Downloads':
[197000,209000,414000,196000,272000,311000,213000,455000,278000]})
print(df1)
plt.figure(figsize=(15,7))
plt.plot(df1['App Price'])
plt.xticks(np.arange(9),df1['APPNAME'])
plt.xlabel('App Name')
plt.ylabel('Price')
plt.show()
58 | P a g e
Output:
import numpy as np
df1=pd.DataFrame({'APPNAME':['AngryBirds','TeamTitans','Marvel
Comics','ColourMe','PUBG','CraxyTaxi','Instagram','WhatsApp','SnapChat'],
'App Price':[75,120,190,245,550,55,175,75,140],
'Total Downloads':
[197000,209000,414000,196000,272000,311000,213000,455000,278000]})
plt.figure(figsize=(15,7))
59 | P a g e
plt.bar(df1['APPNAME'],df1['Total Downloads'])
plt.xticks(np.arange(9),df1['APPNAME'])
plt.xlabel('App Name')
plt.ylabel('Total Downloads')
plt.show()
Source Code:
import numpy as np
60 | P a g e
import matplotlib.pyplot as plt
df1=pd.DataFrame({'APPNAME':['AngryBirds','TeamTitans','Marvel
Comics','ColourMe','PUBG','CraxyTaxi','Instagram','WhatsApp','SnapChat'],
'App Price':[75,120,190,245,550,55,175,75,140],
'Total Downloads':
[197000,209000,414000,196000,272000,311000,213000,455000,278000]})
plt.figure(figsize=(15,7))
est=df1['Total Downloads']/1000
x1=np.arange(9)
x2=x1+0.2
plt.bar(x2,est,color='r',width=0.2,label='Est Downloads')
plt.title('Est Downloads')
plt.xticks(np.arange(9),df1['APPNAME'])
plt.ylabel('App Name')
plt.legend(loc='upper right')
plt.show()
61 | P a g e
Output:
62 | P a g e
PROGRAM-19
Q21 Create a barcharts to see the distribution of rainfall
from Jan to Dec for all the zones
Source Code:
import pandas as pd
import numpy as np
df=pd.DataFrame({'zones':['North','South','East','West','Central'],
'Jan':[140,160,140,180,110],
'Feb':[130,200,180,150,160],
'Mar':[130,130,150,200,130],
'Apr':[190,200,170,120,110],
'May':[160,200,170,120,110],
'Jun':[200,170,140,140,170],
'Jul':[150,110,170,110,130],
'Aug':[170,160,180,130,200],
'Sep':[190,130,190,150,160],
'Oct':[170,140,150,190,160],
'Nov':[150,170,140,110,170],
'Dec':[120,200,170,140,130]})
print(df)
63 | P a g e
df.plot.bar()
plt.show()
Output:
64 | P a g e
MYSQl
PROGRAMS
65 | P a g e
Program-1
Q17.Create a table with the student id, name, and marks
as attributes where the student id is primary key
66 | P a g e
Q21 Create a new table(order ID, customer Name, order
Date) by joining two tables(order ID,customer ID, and
order Date) and (customer ID,customer)
67 | P a g e
Q22 Create a foreign key in one of the two tables
mentioned above
68 | P a g e
Q26. Write a SQL query to order the(student ID,marks)
table in descending order of the marks
69 | P a g e
Program-2
AIM: Create a MYSQL program
OBJECTIVES:
1. Create table FINANCE.
70 | P a g e
4. Display the details of all the rows from Finance table.
71 | P a g e
6. Display details of all the finance records whose
installment is less than 200.
72 | P a g e
9. Display the details of all the loans whose rate of
interest is NULL.
73 | P a g e
12. Display the different interest rates that banks are
charging for various loans excluding NULL.
14. Display the CName and Lamount for all those records
for which either instalments are less than 150 or bank
name is SBI.
74 | P a g e
15. Display the Cname and Lamount for all those loans
amount is either less than 1200000 or irate is more than
11.50.
16. Display the details of all the loans which are financed
in the year 2010.
75 | P a g e
17. Display the details of all the loans whose Lamount is
the range between 800000 and 1500000.
18. Display the details of all the loans whose rate is the
range between 11.00 and 12.00.
76 | P a g e
20. Display the details of all the amounts whose Lamount
is the range 800000 to 1500000.
78 | P a g e
26. Display Accno,C_name and Lamount for all the loans
for which the C_Name contains ’e’ as the last character.
79 | P a g e
28. Display the details of all the loans in descending order
of their ISdate.
80 | P a g e
30. Put the interest rate 11.50 for all the loans for which
the interest rate is NULL.
31. Increase the interest rate by 0.2 for all the loans for
which loan amount is more than 1000000.
81 | P a g e
33. Delete records of all the loans of ‘yabin’.
Informatics Activity
Q1: Identify the network topology in your school?
The network topology used in school is Star topology.
82 | P a g e
i)What is a star topology?
In a star topology, each node is directly connected to a central
device like a hub or switch. It is most popular topology to form Local
Area Network(LAN).
83 | P a g e
Characteristics of Star Topology
All cables run to a central connection point.
If one cable breaks or fails, only the computer that is connected to
that cable is unable to use the network.
A star topology is scalable.
As the network grows or changes, computers are simply added or
removed from the central connection point, which is usually a
hub or a switch.
Cost Factor
there is so much cabling used to connect individual computers to a
central point, this may increase the cost of expanding and
maintaining the network.
Advantages
Easy to setup and expand
Easy to locate fault in case of network failure.
It offers centralized control over the network
Disadvantages
Increases cabling cost since each node is directly
connected to the centre node .
Difficult to expand due to limited connecting points at
centre node or device
84 | P a g e
All nodes are dependant on central node. If the central
device(switch) goes down then entire network breaks
down.
Major Drawback
While star networks are simple in structure, the central
supervisory computer node is a critical point in the
system and failure of this means total failure of the
whole system.
When any device in the network needs to communicate
with another device, a request has to be made to the
central supervisory computer and all data transferred is
routed through this central node.
If the central node is inoperational for any reason then
data communication in the network is stopped.
86 | P a g e
Other functions - MySQL also supports other types of built in
functions but we will limit our lesson to the above named
functions only.
87 | P a g e
CREATE DATABASE - creates a new database
ALTER DATABASE - modifies a database
CREATE TABLE - creates a new table
ALTER TABLE - modifies a table
DROP TABLE - deletes a table
CREATE INDEX - creates an index (search key)
DROP INDEX - deletes an index
ADVANTAGES
It’s Easy To Use
Support Is Readily Available Whenever Necessary
It’s Open-Source (Sort Of)
It’s Incredibly Inexpensive
It’s An Industry Standard (And Still Extremely Popular)
DISADVANTAGES
It’s Got A Few Stability Issues
It Suffers From Relatively Poor Performance Scaling
Development Is Not Community Driven – and Hence
Has Lagged
Its Functionality Tends To Be Heavily Dependant On
Addons
Developers May Find Some Of Its Limitations To Be
Frustrating
88 | P a g e
89 | P a g e