Practical List Ip
Practical List Ip
CLASS XII
INFORMATICS PRACTICES
PRACTICAL LIST
1 Write a NumPy program to create a 3x3 matrix with values ranging from 2 to 10
import numpy as np
x = np.arange(2, 11).reshape(3,3)
print(x)
2 Write a NumPy program to generate six random integers between 25 and 55.
import numpy as np
x = np.random.randint(low=25, high=55, size=6)
print(x)
3 Write a Pandas program to convert a Panda module Series to Python list and it’s type
import pandas as pd
ds = pd.Series([2, 4, 6, 8, 10])
print("Pandas Series and type")
print(ds)
print(type(ds))
print("Convert Pandas Series to Python list")
print(ds.tolist())
print(type(ds.tolist()))
4 Write a Pandas program to compare the elements of the two Pandas Series??
import pandas as pd
ds1 = pd.Series([2, 4, 6, 8, 10])
ds2 = pd.Series([1, 3, 5, 7, 10])
print("Series1:")
print(ds1)
print("Series2:")
print(ds2)
print("Compare the elements of the said Series:")
print("Equals:")
print(ds1 == ds2)
print("Greater than:")
print(ds1 > ds2)
print("Less than:")
print(ds1 < ds2)
c 300
d 400
e 800
dtype: int64
import pandas as pd
d1 = {'a': 100, 'b': 200, 'c':300, 'd':400, 'e':800}
print(‚Dictionary:")
print(d1)
s1 = pd.Series(d1)
print("Converted series:")
print(s1)
6 Write a Pandas program to add, subtract, multiple and divide two Pandas Series
import pandas as pd
ds1 = pd.Series([2, 4, 6, 8, 10])
ds2 = pd.Series([1, 3, 5, 7, 9])
ds = ds1 + ds2
print("Add two Series:")
print(ds)
print("Subtract two Series:")
ds = ds1 - ds2
print(ds)
print("Multiply two Series:")
ds = ds1 * ds2
print(ds)
print("Divide Series1 by Series2:")
ds = ds1 / ds2
print(ds)
9 Write a NumPy program to create a 8x8 matrix and fill it with a checkerboard
pattern.
Checkerboard pattern:
[[0 1 0 1 0 1 0 1]
[1 0 1 0 1 0 1 0]
[0 1 0 1 0 1 0 1]
[1 0 1 0 1 0 1 0]
[0 1 0 1 0 1 0 1]
[1 0 1 0 1 0 1 0]
[0 1 0 1 0 1 0 1]
[1 0 1 0 1 0 1 0]]
import numpy as np
x = np.ones((3,3))
print("Checkerboard pattern:")
x = np.zeros((8,8),dtype=int)
x[1::2,::2] = 1
x[::2,1::2] = 1
print(x)
10 Write a NumPy program to append values to the end of an array. Expected Output:
Original array:
[10, 20, 30]
After append values to the end of the array:
[10 20 30 40 50 60 70 80 90]
import numpy as np
x = [10, 20, 30]
print("Original array:")
print(x)
x = np.append(x, [40, 50, 60,70, 80, 90])
print("After append values to the end of the array:")
print(x)
11 Write a NumPy program to test whether each element of a 1-D array is also present in
a second array
import numpy as np
ar1 = np.array([0, 12, 22, 40, 67])
print("Array1: ",ar1)
ar2 = [0, 22]
print("Array2: ",ar2)
print("Compare each element of array1 and array2")
print(np.in1d(array1, array2))
12 Write a NumPy program to find the number of elements of an array, length of one
array element in bytes and total bytes consumed by the elements
import numpy as np
x = np.array([1,2,3], dtype=np.float64)
print("Size of the array: ", x.size)
print("Length of one array element in bytes: ", x.itemsize)
print("Total bytes consumed by the elements of the array: ",
x.nbytes)
https://pythonclassroomdiary.wordpress.com by Sangeeta M chauhan
13 Write a Pandas program to select the rows where the height is not known, i.e. is NaN.
'name': ['Asha', 'Radha', 'Kamal', 'Divy', 'Anjali'],
'height': [ 5.5, 5, np.nan, 5.9, np.nan],
'age': [11, 23, 22, 33, 22]
import pandas as pd
import numpy as np
pers_data = {'name': ['Asha', 'Radha', 'Kamal', 'Divy',
'Anjali'],
'height': [ 5.5, 5, np.nan, 5.9, np.nan],
'age': [11, 23, 22, 33, 22]}
df = pd.DataFrame(pers__data , index=labels)
print("Persons whose height not known:")
print(df[df['height'].isnull()])
14 Write a Pandas program to select the name of persons whose height is between 5 to
5.5 (both values inclusive)
'name': ['Asha', 'Radha', 'Kamal', 'Divy', 'Anjali'],
'height': [ 5.5, 5, np.nan, 5.9, np.nan],
'age': [11, 23, 22, 33, 22]
import pandas as pd
import numpy as np
pers_data = {'name': ['Asha', 'Radha', 'Kamal', 'Divy',
'Anjali'],
'height': [ 5.5, 5, np.nan, 5.9, np.nan],
'age': [11, 23, 22, 33, 22]}
labels = ['a', 'b', 'c', 'd', 'e']
df = pd.DataFrame(pers__data , index=labels)
print("Persons whose height is between 5 and 5.5")
print(df[(df['height']>= 5 )& (df['height']<= 5.5)])
15 Write a panda program to read marks detail of Manasvi and Calculate sum of all
marks
import pandas as pd
import numpy as np
data = {'Manasvi': ['Physics', 'Chemistry', 'English',
'Maths', 'Computer Sc'],
'marks': [ 89,99,97,99,98],}
df = pd.DataFrame(data )
print("Sum of Marks:")
print(df['marks'].sum())
16 Write a Pandas program to sort the data frame first by 'Designation' in Ascending
order, then by 'Name' in Descending order.
import pandas as pd
https://pythonclassroomdiary.wordpress.com by Sangeeta M chauhan
import pandas as pd
import matplotlib.pyplot as plt
data={'Year':[2000,2002,2004,2006,2008,2010,2012,2014,2016,2018],\
'Production':[4,6,7,15,24,2,19,5,16,4]}
d=pd.DataFrame(data)
print(d)
x=d.hist(column='Production',bins=5,grid=True)
plt.show(x)
18 Write a program to create dataframe for 3 student including name and roll numbers.
and add new columns for 5 subjects and 1 column to calculate percentage. It should
include random numbers in marks of all subjects
import pandas as pd, numpy as np, random
D={‘Roll’:[1,2,3],’Name’:[‘Sangeeta’,’Shanti’,’Swati’]}
P=[]
C=[]
M=[]
E=[]
H=[]
SD=pd.DataFrame(D)
for i in range(3):
P.append(random.randint(1,101))
C.append(random.randint(1,101))
M.append(random.randint(1,101))
E.append(random.randint(1,101))
H.append(random.randint(1,101))
SD[‘Phy’]=P
SD[‘Chem’]=C
SD[‘Maths’]=M
SD[‘Eng’]=E
SD[‘Hin’]=H
SD[‘Total’]=SD.Phy+SD.Chem+SD.Maths+SD.Eng+SD.Hin
SD[‘Per’]=SD.Total/5
print(SD)
19 The table shows passenger car fuel rates in miles per gallon for several years. Make a
LINE GRAPH of the data. During which 2-year period did the fuel rate decrease?
import matplotlib.pyplot as p
Yr=[2000,2002,2004,2006]
rate=[21.0,20.7,21.2,21.6]
p.plot(Yr,rate)
p.show()
20 The number of bed-sheets manufactured by a factory during five consecutive weeks
is given below.
Week First Second Third Fourth Fifth
Number of Bed-sheets 600 850 700 300 900
Draw the bar graph representing the above data
21 The number of students in 7 different classes is given below. Represent this data on
the bar graph.
Class 6th 7th 8th 9th 10th 11th 12th
Number of Students 130 120 135 130 150 80 75
22 The number of students in 7 different classes is given below. Represent this data on
the bar graph.
Class 6th 7th 8th 9th 10th 11th 12th
Number of Students 130 120 135 130 150 80 75
https://pythonclassroomdiary.wordpress.com by Sangeeta M chauhan
23 An analysis has been done in the school to identify hobby of Students as given below.
Hobby Music Dance Games Reading Drawing
Number of Students 130 150 180 75 160
Represent this data on the Pie Chart . Slice colour must be pink,green,blue,gold and
light sky blue
24 The Production(in Tone) by Factory in Years is shown below Represent this data on
the scatter graph.
Year 2000 2005 2010 2015
Production in Tons 50 40 30 60
26 Consider the table given below and write the query for the following
Table: CLUB
27 Consider the tables FLIGHTS & FARES. Write SQL commands for the statements
Table : FLIGHTS
FNO SOURCE DEST NO_OF_FL NO_OF_STOP
IC301 MUMBAI BANGALORE 3 2
IC799 BANGALORE KOLKATA 8 3
MC101 DELHI VARANASI 6 0
IC302 MUMBAI KOCHI 1 4
AM812 LUCKNOW DELHI 4 0
MU499 DELHI CHENNAI 3 3
Table : FARES
FNO AIRLINES FARE TAX_percentage
IC301 Indian Airlines 9425 5
IC799 Spice Jet 8846 10
MC101 Deccan Airlines 4210 7
IC302 Jet Airways 13894 5
AM812 Indian Airlines 4500 6
MU499 Sahara 12000 4
i) Display flight number & number of flights from Mumbai from the table flights.
ii) Arrange the contents of the table flights in the descending order of destination. iii)
Increase the tax by 2% for the flights starting from Delhi.
iv) Display the flight number and fare to be paid for the flights from Mumbai to Kochi using
the tables, Flights & Fares, where the fare to be paid =fare+fare*tax/100.
28 Consider the following tables Employee and salary. Write SQL commands for the statements
(i) to (iv)
Table : Employee
Eid Name Deptid Qualification Sex
1 Deepali Gupta 101 MCA F
2 Rajat Tyagi 101 BCA M
3 Hari Mohan 102 B.A M
4 Harry 102 M.A M
5 Sumit Mittal 103 B.Tech M
6 Jyoti 101 M.Tech F
Table : Salary
Eid Basic DA HRA Bonus
1 6000 2000 2300 200
2 2000 300 300 30
3 1000 300 300 40
4 1500 390 490 30
5 8000 900 900 80
6 10000 300 490 89
(i) To display the frequency of employees department wise.
(ii) To list the names of those employees only whose name starts with ‘H’
(iii) To add a new column in salary table . the column name is total_sal.
(iv) To store the corresponding values in the total_sal column.
29. Observe the following tables and write the queries on the basis the given tables :-
Table: hospital
Name Age Department Charges Gender
1 Arprit 62 Surgery 300 M
2 Zarina 22 ENT 250 F
3 Kareem 32 Orthopaedic 200 M
4 Arun 12 Surgery 300 M
5 Zubin 30 ENT 250 M
6 Kettaki 16 ENT 250 F
7 Ankita 29 Cardiology 800 F
8 Zareen 45 Gynecology 300 F
9 Kush 19 Cardiology 800 M
10 Shilpa 23 Nuclear Medicine 400 F
SCHOOL
CODE TEACHERNAME SUBJECT DOJ PERIODS EXPERIENCE
ADMIN
CODE GENDER DESIGNATION
i) To display TEACHERNAME, PERIODS of all teachers whose periods less than 25.
ii) To display TEACHERNAME, CODE and DESIGNATION from tables SCHOOL and ADMIN
whose gender is male.
iii) To display the number of teachers in each subject.
iv) To display CODE, TEACHERNAME and SUBJECT of all teachers who have joined the
school after 01/01/1999.
30, Design a Django Based Application to obtain a search criteria and fetches record
based on that from Books Table.
31. Design a Django based application that fetches all records from student table of
School database.
32. Design a Django based application that fetches all records of those employees who
are ‘Salesman’