0% found this document useful (0 votes)
3 views

CLASS XII - IP List of Practicals with Coding 2020

The document contains a list of practical exercises for Class XII Informatics Practices, including programming tasks using Python and SQL commands. It covers creating Series and DataFrames with pandas, data visualization using matplotlib, and SQL queries for managing data in tables. Each exercise includes a solution with code snippets and expected outputs.

Uploaded by

poonampareek985
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

CLASS XII - IP List of Practicals with Coding 2020

The document contains a list of practical exercises for Class XII Informatics Practices, including programming tasks using Python and SQL commands. It covers creating Series and DataFrames with pandas, data visualization using matplotlib, and SQL queries for managing data in tables. Each exercise includes a solution with code snippets and expected outputs.

Uploaded by

poonampareek985
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

LIST OF PRACTICALS

CLASS XII
INFORMATICS PRACTICES
1. Write a program to create a Series object using an Nd-array that has 10 elements
in the range 100 to 200?
Solution:
import numpy as np
import pandas as pd
s = pd.Series(np.linspace(110,200,10))
print(s)
Output

2. Write a program to create a Series object using a dictionary that stores the number
of students in each section of class 12 in your school?
Solution:
import pandas as pd
students = {'A':39,'B':41,'C':42,'D':44}
s1 = pd.Series(students)
print(s1)
Output
3. Consider the series object S that stores the contribution of each section, as shown
below:
A 4300
B 6500
C 3900
D 6100

Write code to modify the amount of section ‘A’ as 3400 and for section ‘C’ and ‘D’ as
5000. Print the changed object.
Solution:
import pandas as pd
D = {'A':4300,'B':6500,'C':3900,'D':6100}
S = pd.Series(D)
S[0] = 3400
S[2:] = 5000
print(S)
Output

4. Write a program to create a Data Frame Quarterly Sales where each row contains
the Quarterly Sales of TV, Freeze and AC. Show the DataFrame after deleting details
of Freeze.
Solution:
import pandas as pd
PData = {
'TV' : {'QTR1' : 200000, 'QTR2': 230000, 'QTR3' : 210000, 'QTR4':24000},
'Freeze' : {'QTR1' : 300000, 'QTR2': 200000, 'QTR3' : 290000, 'QTR4':210000},
'AC' : {'QTR1' : 240000, 'QTR2': 153000, 'QTR3' : 245000, 'QTR4':170000}
}
df = pd.DataFrame(PData)
print(df)
del df['Freeze']
print(df)
Output

5. Write a program to create a DataFrame to store Roll Number, Name and Marks of
five students. Print the DataFrame and its transpose.
Solution:
import pandas as pd
PData = {
'Roll Number' : [101,102,103,104,105],
'Name' : ['Karan','Taran','Piyush','Bhupinder','Simran'],
'Marks' : [82,85,79,86,94]
}
df = pd.DataFrame(PData)
print("Original DataFrame")
print(df)
print("DataFrame after Transpose")
print(df.T)
Output
6. Write a program to create a DataFrame from a CSV file. Display the shape
(Number of rows and columns) of the CSV file.
Solution:
import pandas as pd
df = pd.read_csv('F://PP.csv') # All Columns
print(df)
rows, columns = df.shape
print("Number of rows : ",rows)
print("Number of columns : ",columns)
Output

7. Write a program to create a DataFrame which contains RollNumber, Name, Height


and Weight of 05 students. Create a CSV file using this DataFrame.
Solution:
import pandas as pd
PData = {
'Roll Number' : [101,102,103,104,105],
'Name' : ['Karan','Taran','Piyush','Bhupinder','Simran'],
'Height' : [5.4,5.9,4.8,4.11,5.1],
'Weight' : [54,52,49,46,53]
}
df = pd.DataFrame(PData)
print("DataFrame")
print(df)
df.to_csv('dataStudents.csv',sep='\t',index=False,header=['Roll Number','Name
of Student','Height','Weight'],columns=['Roll Number','Name','Height','Weight'])
print("Data stored in csv file")
Output

8. Given the school result data, analyses the performance of the students in
Accountancy and Business studies using bar graph.
Solution:
import matplotlib.pyplot as plt
import numpy as np
label = ['Anil', 'Vikas', 'Dharma', 'Mahen', 'Manish', 'Rajesh']
Accountancy = [94,85,45,25,50,54]
BusinessStudy =[98,76,34,65,55,88]
index = np.arange(len(label))
plt.bar(index, Accountancy,label="Accountancy", color='g')
plt.bar(index+0.3, BusinessStudy,label = "Business Study", color='r')
plt.xlabel('Student Name', fontsize=12)
plt.ylabel('Percentage', fontsize=12)
plt.xticks(index, label, fontsize=12, rotation=90)
plt.title('Percentage of Marks achieve by student Class XII')
plt.legend()
plt.show()
Output

9. Given datasets population of India and Pakistan in the given years. Show the
population of India and Pakistan using line chart with title and labels of both axis.
Year 1960 1970 1980 1990 2000 2010
Population of Pakistan 44.91 58.09 78.07 107.7 138.5 170.6
Population of India 449.48 553.57 696.783 870.133 1000.4 1309.1
Solution:
from matplotlib import pyplot as plt
year = [1960, 1970, 1980, 1990, 2000, 2010]
pop_pakistan = [44.91, 58.09, 78.07, 107.7, 138.5, 170.6]
pop_india = [449.48, 553.57, 696.783, 870.133, 1000.4, 1309.1]
plt.plot(year, pop_pakistan, color='k')
plt.plot(year, pop_india, color='orange')
plt.xlabel('Countries')
plt.ylabel('Population in million')
plt.title('Pakistan India Population till 2010')
plt.show()import matplotlib.pyplot as plt
plt.show()
Output
10. Write a program to plot a bar chart from the medals won by four countries. Make
sure that bars are separately visible.
Solution:
from matplotlib import pyplot as plt
import numpy as np
plt.figure(figsize = (10,7))
info = ['Gold','Silver','Bronze','Total']
India = [80,59,59,198]
England = [45,45,46,136]
Australia = [26,20,20,66]
Canada = [15,40,27,82]
X = np.arange(len(info))
plt.bar(info,India,width = 0.15,label="India")
plt.bar(X + 0.15,England,width = 0.15,label="England")
plt.bar(X + 0.30,Australia,width = 0.15,label="Australia")
plt.bar(X + 0.45,Canada,width = 0.15,label = "Canada")
plt.xlabel('Medal Type')
plt.ylabel('Medals')
plt.title('Medals won by four countries')
plt.legend()
plt.show()
Output
11. A survey gathers height and weight of 60 participants and recorded the
participants’ ages as:
Ages = [1,1,2,3,5,7,8,9,10,10,11,13,13,15,16,17,18,19,20,21,21,23,24,24,24,25,25,
25,25,26,26,26,27,27,27,27,27,29,30,30,30,30,31,33,34,34,34,35,36,36,37,37,37,3
8,38,39,40,40,41,41]
Write a program to plot a histogram from above data with 20 bins.
Solution:
from matplotlib import pyplot as plt
Ages = [1,1,2,3,5,7,8,9,10,10,11,13,13,15,16,17,18,19,20,
21,21,23,24,24,24,25,25, 25,25,26,26,26,27,27,27,
27,27,29,30,30,30,30,31,33,34,34,34,35,36,36,37,
37,37,38,38,39,40,40,41,41]
plt.hist(Ages,bins = 20)
plt.title("Participants' Ages Histogram")
plt.show()
Output
12. Write a program to create data series and then change the indexes of the Series
object in any random order.
Solution:
import pandas as pd
import numpy as np
s1 = pd.Series(data = [100,200,300,400,500], index = ['I','J','K','L','M'])
print("Original Data Series")
print(s1)
s1 = s1.reindex(index = ['K','L','M','J','I'])
print("Data Series after changing the index")
print(s1)
Output

13. In an online contest, two 2-player teams’ point in 4 rounds are stored in two
DataFrames as shown below:
Team 1’s points (df1) Team 1’s points (df2)
P1 P2 P1 P2
1 700 490 1 1100 1400
2 975 460 2 1275 1260
3 970 570 3 1270 1500
4 900 590 4 1400 1190

Write a program to calculate total points earned by both the teams in each round.
Solution:
import pandas as pd
data1 = {'P1' : {'1':700,'2':975,'3':970,'4':900},
'P2' : {'1':490,'2':460,'3':570,'4':590}}
data2 = {'P1' : {'1':1100,'2':1275,'3':1270,'4':1400},
'P2' : {'1':1400,'2':1260,'3':1500,'4':1190}}
df1 = pd.DataFrame(data1)
df2 = pd.DataFrame(data2)
print("Performace of Team - 1")
print(df1)
print("Performace of Team - 2")
print(df2)
print("Points earned by both Teams")
print(df1 + df2)
Output

14. Write a program to create a DataFrame with two columns name and age. Add a
new column Updated Age that contains age increased by 10 years.
Solution:
import pandas as pd
data = {'Name' : ['Amit','Sumit','Rahul','Dev'],
'Age' : [20,22,16,15]
}
df = pd.DataFrame(data)
print("Original DataFrame")
print(df)
df['Updated Age'] = df['Age'] + 10
print("DataFrame After adding column Updated Age")
print(df)
Output

15. Given a DataFrame ( df ) as under:

City Schools
Delhi 7654
Mumbai 8700
Kolkata 9800
Chennai 8600

Write a program to print DataFrame one row at a time. Also display first two rows of
City column and last two rows of Schools column.
Solution:
import pandas as pd
data = {'City' : ['Delhi','Mumbai','Kolkata','Chennai'],
'Schools' : [7654,8700,9800,8600]
}
df = pd.DataFrame(data)
for i, j in df.iterrows():
print(j)
print("-----------------------")
print("*******************************")
print("First two rows of City Column")
print(df.City.head(2))
print("*******************************")
print("Last two rows of Schools Column")
print(df.Schools.tail(2))
Output

16. Write a program to plot a horizontal bar chart from heights of some stdents.
Solution:
import matplotlib.pyplot as plt
import numpy as np
Names = ['Ram','Shyam','Rama','Kashish','Mayank']
Heights = [5.1,5.5,6.0,5.0,6.3]
Weights = [20,30,15,18,22]
X = np.arange(len(Names))
plt.barh(Names,Heights, height = 0.5,label = "Height", color ='g')
plt.barh(X+0.5,Weights, height =0.5,label = "Weight", color ='b')
plt.xlabel("Height")
plt.ylabel("Names")
plt.legend()
plt.show()
Output
17. Write SQL commands on the basis of the following tables.
Table: PROUDCT

PID Productname Manufacturer Price


TP01 Talcum Powder LAK 40
FW05 Face Wash ABC 45
BS01 Bath Soap ABC 55
SH06 Shampoo XYZ 120
FW12 Face Wash XYZ 95

1) Display details of those products whose manufacturere is “ABC”.

SELECT * FROM PRODUCT WHERE Manufacturer = “ABC”;

2) Display details of Products whose price is in range of 50 to 100.

SELECT * FROM PRODUCT WHERE Price BETWEEN 50 AND 100;

3) Display Product Name and Price from table Product where product name starts
with “B”.

SELECT ProductName, Price

FROM PRODUCT

WHERE Productname like ‘B%’

4) Increase the price of all products by 10.

UPDATE PRODUCT SET PRICE = PRICE + 10;


5) Display details of products in ascending order of price.

SELECT * FROM PRODUCT ORDER BY PRICE ASC;

18. Consider the following tables HOSPITAL. Write SQL commands for (i) to (iv) and
give outputs for SQL queries (v) to (viii).
No Name Age Department Dateofadmin Charge Sex
1 Arpit 62 Surgery 21/01/06 300 M
2 Zayana 18 ENT 12/12/05 250 F
3 Kareem 68 Orthopedic 19/02/06 450 M
4 Abhilash 26 Surgery 24/11/06 300 M
5 Dhanya 24 ENT 20/10/06 350 F
6 Siju 23 Cardiology 10/10/06 800 M
7 Ankita 16 ENT 13/04/06 100 F
8 Divya 20 Cardiology 10/11/06 500 F
9 Nidhin 25 Orthopedic 12/05/06 700 M
10 Hari 28 Surgery 19/03/06 450 M

(i) To show all information about the patients whose names are having six
characters only.

SELECT *
FROM Hospital
WHERE length(name) = 6;
(ii) To reduce Rs. 200 from the charge of female patients who are in Cardiology
department.

UPDATE Hospital
SET Charge = Charge – 200
WHERE Sex = ‘F’ AND Department = ‘Cardiology’;
(iii) To insert a new row in the above table with the following data :

11, ‘Rakesh’, 45, ‘ENT’, {08/08/08}, 1200, ‘M’

INSERT INTO Hospital


VALUES(11, ’Rakesh’, 45, ’ENT’ , ’2008/08/08’,1200,’M’);
(iv) To remove the rows from the above table where age of the patient > 60.

DELETE FROM Hospital


WHERE Age > 60;

(v) Select SUM(Charge) from HOSPITAL where Sex=’F’;

Sum(Charge)
1200

(vi) Select COUNT(DISTINCT Department ) from HOSPITAL;

COUNT(DISTINCT Department )
4

(vii) Select Department, SUM(Charge) from HOSPITAL group by Department;

Department Sum(Charge)
Cardiology 1300
ENT 700
Orthopedic 1150
Surgery 1050

(viii) Select Name from HOSPITAL where Sex=’F’ AND Age > 20;

Name
Zayana
Dhanya

You might also like