Worksheet Class Xii Ip 2023-24
Worksheet Class Xii Ip 2023-24
Worksheet Class Xii Ip 2023-24
SESSION: 2023-24
1|P age
CHIEF PATRON
PATRON
2|Page
MENTOR
RAKSHA PARMAR, PGT (CS) ASHISH KUMAR CHAURDIA, MAYURI PATEL, PGT (CS)
KV SABARMATI PGT (CS) KV SILVASSA
KV NO. 2 EME, BARODA
VIVEK KUMAR GUPTA, PGT NAMRATA SHAH, PGT (CS) KAMLESH AMIN, PGT (CS)
(CS) KV ONGC MEHSANA KV NO. 3 SU JAMNAGAR
KV ONGC ANKLESHWAR
3|Page
INDEX
PAGE NO.
UNIT UNIT NAME
NO.
FROM TO
4|Page
PRACTICAL MARKS DISTRIBUTION
5|Page
KENDRIYA VIDYALAYA SANGATHAN, AHEMDABAD REGION
CLASS XII – IP NAME OF CHAPTER: Series
TOPIC: Series (Create Series, Access element, Filter value)
WORKSHEET NO. 1
QN. Questions M
1 Write a program to create a series to print scalar value “5” four times. 2
2 Write a program to create a series object F1 using a dictionary that stores 2
the number of furniture in each lab of your school.
Note: Assume four furniture names are Table, Sofa, Chair and stool having
40, 2,45,26 items respectively and pandas library has been imported as pd.
3 What will be the output of the following code: 1
import pandas as pd
L= [9,10,12]
S=pd.Series(L)
Dbl=pd.Series(data = S*2)
print(“New Series: “)
print(Dbl)
4 Write a program to create a series object using a dictionary that stores the 2
number of students in each house of CLASS 12D of your school.
Note: Assume four house names are Beas, Chenab, Ravi and Satluj having
18, 2, 20, 18 students respectively and pandas library has been imported
as pd.
5 What will be the output of the following code: 1
>>>import pandas as pd
>>>A=pd.Series(data=[35,45,55,40])
>>>print(A==data)
What will be the output:
a. True b. False c. [35,45,55,40] d. Error
6 Find the output of following program. import numpy as np 1
d=np.array([10,20,30,40,50,60,70])
print(d [-4:])
7 What will be the output of the following code: 1
>>>import pandas as pd
>>>A=pd.Series(data=[35,45,55,40])
>>>print (A[A>45])
8 Write the output of the given command: import pandas as pd 1
s=pd.Series([1,2,3,4,5,6],index=['A','B','C','D','E','F'])
print(s[s%2==0])
9 What will be the output of the following code: 1
>>>import pandas as pd
>>>A=pd.Series(data=[35,45,55,40])
>>>print ([A>45])
10 What will be the output of the following code: 1
>>>import pandas as pd
>>>A=pd.Series(data=[35,45,55,40])
>>>A[2:5]=25
>>>print (A)
11 Write a program to create a series object comp using a list that stores the 2
number of quantity of computer item in lab of your school. Note: Assume four
computer item names as index are KB, Mouse, computer and printer
havingvalues are 30, 25, 20, 2 items respectively and pandas library has been
imported as pd.
6|Page
KENDRIYA VIDYALAYA SANGATHAN, AHEMDABAD REGION
CLASS XII – IP
NAME OF CHAPTER: Series
TOPIC: Series (Create Series, Access element, Filter value)
WORKSHEET NO. 1
QN. Answers M
1 import pandas as pd 2
S=pd.Series(5, index=[1,2,3,4,5])
2 import pandas as pd 2
F={‘Table’ :40, ‘Sofa’ :2, ‘Chair’ :45, ‘Stool’ :26}
F1=pd.Series(St)
3 1
4 import pandas as pd 2
St={‘Beas’ :18, ‘Chenab’ :20, ‘Ravi’ :20, ‘Satluj’ :18}
S1=pd.Series(St)
5 d. Error 1
6 [40 50 60 70] 1
7 2 55 1
dtype: int64
8 B 2 1
D 4
F 6
dtype: int64
9 0 False 1
1 False
2 True
3 False
dtype: bool
10 0 35 1
1 45
2 25
3 25
dtype: int64
11 >>> i=['KB', 'Mouse', 'computer’,'printer'] 2
>>> data=[30, 25, 20, 2]
>>> comp=pd.Series(data, index=i)
>>> print(comp)
***
7|P age
KENDRIYA VIDYALAYA SANGATHAN, AHEMDABAD REGION
CLASS XII – IP
NAME OF CHAPTER: Series
TOPIC: Series Attribute and methods
WORKSHEET NO. 2
Q. Questions M
No
1 Which attribute is used to get total number of elements in a Series? 1
a. size b. itemsize
c. shape d. ndim
2 To display last five rows of a series object ‘S’, you may write: 1
a. S.Head()
b. S.Tail(5)
c. S.Head(5)
d. S.tail()
3 To display top five rows of a series object ‘S’, you may write: 1
a. S.head()
b. S.Tail(5)
c. S.Head(5)
d. S.tail()
4 _________________method in Pandas can be used to change the index 1
of rows and columns of a Series or DataFrame:
(i) rename() (ii) reindex() (iii) reframe() (iv) none of the above
5 CSV stands for ______________ 1
6 Pandas Series is: _____ 1
a. 2-Dimensional b. 3-Dimensional c. 1 Dimensional d. Multidimensional
7 Python pandas was developed by:___________ 1
a. Guido van Rossum b. Travis Oliphant
c. Wes McKinney d. Brendan Eich
8 The command to install the pandas is: 1
a. install pip pandas b. install pandas
c. pip pandas d. pip install pandas
9 The name “Pandas” is derived from the term: 1
a. Panel Data b. Panel Series
c. Python Document d. Panel Data Frame
10 We can analyse the data in pandas with 1
a. Series b. Data Frame
c. Both of the above d. None of the above
11 Pandas is a: __________ 1
a. Package b. Language
c. Library d. Software
12 Which of the following import statement is not correct? 1
a. import pandas as CLASS12 b. import pandas as 1pd
c. import pandas as pd1 d. import pandas as pd
13 Which of the following is not an attribute of pandas data frame? 1
a. length b. T
c. Size d. shape
14 import pandas as pd 1
s=pd.Series([1,2,3,4,5], index=['akram','brijesh','charu','deepika','era'])
8|Page
print(s['charu'])
a. 1 b. 2 c. 3 d. 4
15 Assuming the given series, named stud, which command will be used to 1
print 5 as output?
Amit 90
Ramesh 100
Mahesh 50
john 67
Abdul 89
Name: Student, dtype: int64
a. stud.index b. stud.length
c. stud.values d. stud.size
16 A social science teacher wants to use a pandas series to teach about Indian 1
historical monuments and its states. The series should have the monument
names as values and state names as indexes which are stored in the given
lists, as shown in the code. Choose the statement which will create the
series:
import pandas as pd
Monument=['Qutub Minar','Gateway of India','Red Fort','Taj Mahal']
State=['Delhi','Maharashtra','Delhi','Uttar Pradesh']
a. S=df.Series(Monument, index=State)
b. S=pd.Series(State, Monument)
c. S=pd.Series(Monument, index=State)
d. S=pd.series(Monument, index=State)
17 Difference between loc() and iloc().: 1
a. Both are Label indexed based functions.
b. Both are Integer position-based functions.
c. loc() is label-based function and iloc() integer position-based function.
d. loc() is integer position-based function and iloc() index position-based
function.
18 Method or function to add a new row in a Series is: 1
a. .locate() b. .loc()
c. join d. add()
19 Rasha wants to set all the values to zero in Series, choose the right 1
command to do so:
a. S1=0 b. S1[]=0
c. S1[:]=0 d. S1[:]==0
20 Write the output of the given program: import pandas as pd 1
S1=pd.Series([5,6,7,8,10],index=['v','w',' x','y','z'])
Output required (5,)
a. print(S1.shape()) b. print(S1.shape)
c. print(S1.values) d. print(S1.size())
21 To check if the Series object contains NaN values, attribute is display. 1
a. hasnan b. nbytes
c. ndim d. hasnans
***
9|Page
KENDRIYA VIDYALAYA SANGATHAN, AHEMDABAD REGION
CLASS XII – IP
NAME OF CHAPTER :Series
TOPIC: Series Attribute and methods
WORKSHEET NO. 2
QN. Answers M
1 Size 1
2 s.tail() 1
3 s.head() 1
4 reindex() 1
5 Comma separated value 1
6 c. 1 Dimensional 1
7 c. Wes McKinney 1
8 d. pip install pandas 1
9 a. Panel Data 1
10 c. Both of the above 1
11 c. Library 1
12 b. import pandas as 1pd 1
13 a. length 1
14 c. 3 1
15 d. stud.size 1
16 d. S=pd.Series(Monument,index=State) 1
17 c. loc() is label based function and iloc() integer position based function. 1
18 b.loc() 1
19 S1[:]=0 1
20 b. print(S1.shape) 1
21 (d) hasnans
10 | P a g e
KENDRIYA VIDYALAYA SANGATHAN, AHEMDABAD REGION
CLASS XII – IP
NAME OF CHAPTER: Series
TOPIC: Vector operation, slicing
WORKSHEET NO. 3
QN Questions M
.
1 Consider the following series named animal: 2
dtype: object
Write the command that generates the output as:
2 Green
4 Yellow
dtype: object
6 What will be the output of the given code? 2
import pandas as pd
s=pd.Series([3,6,9,12,14],index=['a','
b','c','d','e']) print(s[‘a’]+s[‘c’])
11 | P a g e
7 2
TOTAL
***
12 | P a g e
KENDRIYA VIDYALAYA SANGATHAN, AHEMDABAD REGION
CLASS XII – IP
NAME OF CHAPTER: Series
TOPIC: Vector operation, slicing
WORKSHEET NO. 3
Q. Answers M
No.
1 W Wolf 2
B Bear
dtype: object
2 x NaN 2
a NaN
v -1.0
w 2.0
y 2.0
z 8.0
dtype: float64
3 2 Raj 2
5 Ankur
6 Harsh
dtype: object
2 Raj
5 Ankur
dtype: object
4 0 Dance 2
1 Music
2 300
3 400
4 500
5 Color[2:5:2] 2
6 12 2
7 2
8 5
s1
0 5
1 6
13 | P a g e
2 7
3 8
4 9
9 i)India NewDelhi 4
UK London
Japan Tokyo
dtype: object
ii) CapCntry[5:1:-1]
China Beijing
Japan Tokyo
France Paris
UK London
dtype: object
iii) CapCntry[: :-1]
China Beijing
Japan Tokyo
France Paris
UK London
USA WashingtonDC
India NewDelhi
dtype: object
iv) CapCntry[3:]
France Paris
Japan Tokyo
China Beijing
dtype: object
10 Line1: import pandas as pd 1
Line2: import_numpy as np # Library name
Line3: A=np.array(2,11,2) # function name to get numpy
array
Line 4: S=pd.Series(_A_____, Index=[_0,1,2]) # Data name and
indexes
Line 5: Print(S)
TOTAL
14 | P a g e
KENDRIYA VIDYALAYA SANGATHAN, AHEMDABAD REGION
CLASS XII – IP
NAME OF CHAPTER: DATA FRAME
TOPIC: CREATE DATA FRAME by various method
Remove row and column of DataFrame
WORKSHEET NO. 4
QN Questions M
1 Write a Python code to create a DataFrame stock with appropriate 2
column headings from the list given below:
[[101,'Gurman',98], [102,'Rajveer',95], [103,'Samar' ,96],
[104,'Yuvraj',88]]
15 | P a g e
import pandas as pd
Year1={'Q1':5000,'Q2':8000,'Q3':12000,'Q4': 18000}
Year2={'A' :13000,'B':14000,'C':12000}
totSales={1:Year1,2:Year2}
df=pd.DataFrame(totSales)
print(df)
8 Consider the given DataFrame ‘Stock’: 4
Name Price
0 Nancy Drew 150
1 Hardy boys 180
2 Diary of a wimpy kid 225
3 Harry Potter 500
Write suitable Python statements for the following:
i. Add a column called Special_Price with the following
data: [135,150,200,440].
ii. Add a new book named ‘The Secret' having price 800.
iii. Remove the column Price.
iv.Remove first and third rows from DataFrame
9 Consider the given DataFrame df: 4
Q1 Q2 Q3 Q4
0 5000 8000 12000 18000
1 10 20 30 40
Write suitable Python statements for the following:
i. Add a column called Q5 with the following data:
[2000,44].
ii. Add a new record with appropriate values.
iii. Remove the column Q2, Q4.
iv.Remove first and second rows from DataFrame.
10 Write a python code to create empty DataFrame 1
TOTAL
***
16 | P a g e
KENDRIYA VIDYALAYA SANGATHAN, AHEMDABAD REGION
CLASS XII – IP
NAME OF CHAPTER: DATA FRAME
TOPIC: CREATE DATA FRAME by various method
Remove row and column of DataFrame
QN Answers M
1 import pandas as pd 2
d=[[101,'Gurman',98],[102,'Rajveer',95],[103,'Samar'
,96],[104,'Yuvraj',88]]
c=['sno','Name','Score']
stock=pd.DataFrame(d,columns=c)
print(stock)
2 import pandas as pd 2
d=[['Nancy Drew',150],\
['Hardy boys',180],\
['Diary of a wimpy kid',225],\
['Harry Potter',500]]
c=['Name','Price']
stock=pd.DataFrame(d,columns=c)
print(stock)
3 d={'Name':['Nancy Drew','Hardy boys','Diary of a wimpy kid','Harry 2
Potter] 'Price':[150,180,225,500]}
stock =pd.DataFrame(d)
print(stock)
4 s1=pd.Series(['Nancy Drew','Hardy boys','Diary of a wimpy 2
kid','Harry Potter'])
s2=pd.Series([150,180,225,500])
d ={'Name':s1,'Price':s2}
stock=pd.DataFrame(d)
print(stock)
5 Q1 Q2 Q3 Q4 2
0 5000 8000 12000 18000
1 10 20 30 40
6 1 2
17 | P a g e
Q1 [5000, 10]
Q2 [8000, 20]
Q3 [12000, 30]
7 1 2 2
Q1 5000.0 NaN
Q2 8000.0 NaN
Q3 12000.0 NaN
Q4 8000.0 NaN
A NaN 13000.0
B NaN 14000.0
C NaN 12000.0
Index=[‘Q1’,’Q2’,’Q3’.’Q4’,’A’,’B’,’C’]
Columns=[1,2]
8 i. stock[‘Special_Price ‘]=[135,150,200,440] 4
ii. stock.loc[‘The Secret']=800
iii. stock.drop([‘Price’],axis=1,inplace=True)
iv. stock.drop([0,2],axis=0,inplace=True)
9 i. df['Q5']=[2000,44] 4
ii. df.loc[2]=[100,200,300,400,500]
iii. df.drop(['Q2','Q4'],axis=1,inplace=True)
iv. df.drop([0,1],axis=0,inplace=True)
10 import pandas as pd 1
df=pd.DataFrame()
print(df)
TOTAL
***
18 | P a g e
KENDRIYA VIDYALAYA SANGATHAN, AHEMDABAD REGION
CLASS XII – IP
NAME OF CHAPTER: DATA FRAME
TOPIC: CREATE DATA FRAME by various method
Remove row and column of DataFrame
WORKSHEET NO. 5
QN Questions M
1 Write a Python code to create a DataFrame with appropriate column 2
headings from the csv file given below:
city Maxtemp Mintemp Rainfall
0 Delhi 40 32 24.1
1 Bengaluru 31 25 36.2
2 Chennai 35 27 40.8
3 Mumbai 29 21 35.2
19 | P a g e
7 What will be the output of following code and Answer the following: 2
i. List the index of the DataFrame df
ii. List the column names of DataFrame df.
import pandas as pd
x={'Qtr1':5000,'Qtr2':8000,'Qtr3':12000,'Qtr4': 18000}
y={'p' :13000,'q':14000,'r':12000}
totSales={1:x,2:y}
df=pd.DataFrame(totSales)
print(df)
8 Consider the given DataFrame ‘temp’: 4
city Maxtemp Mintemp Rainfall
0 Delhi 40 32 24.1
1 Bengaluru 31 25 36.2
2 Chennai 35 27 40.8
3 Mumbai 29 21 35.2
Write suitable Python statements for the following:
i. Add a column called area with the following data:
[135455,153330,225000,442540].
ii. Add a new city named ‘calcutta having maxtemp 20,mintemp 12
and rainfall
iii. Remove the column rainfall.
iv. iv.Remove first and third rows from DataFrame
9 Consider the given DataFrame df: 4
Qtr1 Qtr2 Qtr3 Qtr4
0 5000 8000 12000 18000
1 10 20 30 40
Write suitable Python statements for the following:
i. Add a column called Qtr5 with the following data:
[1444,20].
ii. Add a new record with appropriate values.
iii. Remove the column Qtr1, Qtr3.
iv. iv.Remove first and second rows from DataFrame.
10 Write a python code to create empty DataFrame 1
TOTAL
***
20 | P a g e
KENDRIYA VIDYALAYA SANGATHAN, AHEMDABAD REGION
CLASS XII – IP
NAME OF CHAPTER: DATA FRAME
TOPIC: CREATE DATA FRAME by various method
Remove row and column of DataFrame
import pandas as pd
df=pd.read_csv(r"C:\Users\rasha\OneDrive\Desktop\a.csv")
print(df)
2 import pandas as pd 2
d=[['Delhi',40,32,24.1],['Bengaluru',31,25,36.2],['Chennai',35,27,40.8]
,['Mumbai',29,21,35.2]]
c=['city','Maxtemp','Mintemp','Rainfall']
temp=pd.DataFrame(d,columns=c)
print(temp)
3 import pandas as pd 2
d={'city':['Delhi','Bengaluru','Chennai','Mumbai'],\
'Maxtemp':[40,31,35,29],\
'Mintemp':[32,25,27,21],\
'Rainfall':[24.1,36.2,40.8,35.2]}
temp=pd.DataFrame(d)Stock =pd.DataFrame(d)
print(temp)
4 import pandas as pd 2
s1=pd.Series(['Delhi','Bengaluru','Chennai','Mumbai'])
s2=pd.Series([40,31,35,29])
s3=pd.Series([32,25,27,21])
s4=pd.Series([24.1,36.2,40.8,35.2])
d={'city':s1,'Maxtemp':s2,'Mintemp':s3,'Rainfall':s4}
temp=pd.DataFrame(d)
print(temp)
21 | P a g e
5 Qtr1 Qtr2 Qtr3 Qtr4 2
0 5000 8000 12000 18000
1 10 20 30 40
6 1 2
Qtr1 [5000, 10]
Qtr2 [8000, 20]
Qtr3 [12000, 30]
7 1 2 2
Qtr1 5000.0 NaN
Qtr2 8000.0 NaN
Qtr3 12000.0 NaN
Qtr4 18000.0 NaN
p NaN 13000.0
q NaN 14000.0
r NaN 12000.0
Index=[‘Qtr1’,’Qtr2’,’Qtr3’.’Qtr4’,’p’,’q’,’r’]
Columns=[1,2]
8 i. temp[‘area ‘]=[135,150,200,440] 4
ii. temp.loc[4]=[‘calcutta',20,12,10.2,252522]
iii. temp.drop([‘rainfall’],axis=1,inplace=True)
iv. temp.drop([0,2],axis=0,inplace=True)
9 i. df['Qtr5']=[1444,20] 4
ii. df.loc[2]=[11,22,33,40,50]
iii. df.drop(['Qtr1','Qtr3'],axis=1,inplace=True)
iv. df.drop([0,1],axis=0,inplace=True)
10 import pandas as pd 1
df=pd.DataFrame()
print(df)
TOTAL
22 | P a g e
KENDRIYA VIDYALAYA SANGATHAN, AHEMDABAD REGION
CLASS XII – IP
NAME OF CHAPTER: DATA FRAME
TOPIC: CREATE DATA FRAME by various method
Remove row and column of DataFrame
WORKSHEET NO. 6
Q. Questions M
No
1 Write a Python code to create a DataFrame ‘lib’ with appropriate column 2
headings from the csv file given below:
Pcd title Price qty
0 P01 Notebook 85 500
1 P02 Pencilbox 76 200
2 P03 WaterBottle 129 50
3 P04 SchoolBag 730 70
2 Write a Python code to create a DataFrame ‘lib’ by using list: 2
Pcd title Price qty
0 P01 Notebook 85 500
1 P02 Pencilbox 76 200
2 P03 WaterBottle 129 50
3 P04 SchoolBag 730 70
3 Write a Python code to create a DataFrame ‘lib’ by using dictionary 2
method:
Pcd title Price qty
0 P01 Notebook 85 500
1 P02 Pencilbox 76 200
2 P03 WaterBottle 129 50
3 P04 SchoolBag 730 70
4 Write a Python code to create a DataFrame ‘lib’ by using Series method: 2
Pcd title Price qty
0 P01 Notebook 85 500
1 P02 Pencilbox 76 200
2 P03 WaterBottle 129 50
3 P04 SchoolBag 730 70
5 Write a Python code to display output of Transpose of DataFrame . 2
Pcd title Price qty
0 P01 Notebook 85 500
1 P02 Pencilbox 76 200
2 P03 WaterBottle 129 50
3 P04 SchoolBag 730 70
6 Write a Python code to create a DataFrame ‘lib’ with appropriate column 2
headings save the DataFrame in sample.csv:
Pcd title Price qty
0 P01 Notebook 85 500
1 P02 Pencilbox 76 200
2 P03 WaterBottle 129 50
3 P04 SchoolBag 730 70
7 Write a Python code to create a DataFrame ‘temp’ and save the 2
DataFrame in temp.csv file
23 | P a g e
city Maxtemp Mintemp Rainfall
0 Delhi 40 32 24.1
1 Bengaluru 31 25 36.2
2 Chennai 35 27 40.8
3 Mumbai 29 21 35.2
8 Consider the given DataFrame: 4
Pcd title Price qty
0 P01 Notebook 85 500
1 P02 Pencilbox 76 200
2 P03 WaterBottle 129 50
3 P04 SchoolBag 730 70
Write suitable Python statements for the following:
i. Add a column called ACC_NO with the following data:
[135,153,225,442].
ii. Add a new Record
iii. Remove the column qty.
iv. Remove first and third rows from DataFrame
24 | P a g e
KENDRIYA VIDYALAYA SANGATHAN, AHEMDABAD REGION
CLASS XII – IP
NAME OF CHAPTER: DATA FRAME
TOPIC: CREATE DATA FRAME by various method
Remove row and column of DataFrame
QN Answers M
1 2
import pandas as pd
lib=pd.read_csv(r"C:\Users\rasha\OneDrive\Desktop\a.csv")
print(lib)
2 import pandas as pd 2
d=[[‘P01’,’Notebook’,85,500],[ ‘P02’,’Pencilbox’,76,200], [‘P03’,
‘WaterBottle’,129,50],[ ‘P04’,’SchoolBag’,730,70]]
c=['Pcd','title','Price','qty']
lib=pd.DataFrame(d,columns=c)
print(lib)
3 import pandas as pd 2
d={'Pcd':['P01','P02','P03','P03'],\
'title':[40,31,35,29],\
'Price'':[85,76,129,730],\
'qty':[500,200,50,70]}
lib=pd.DataFrame(d)
print(lib)
4 import pandas as pd 2
s1=pd.Series(['P01','P02','P03','P03'])
s2=pd.Series([40,31,35,29])
s3=pd.Series([85,76,129,730])
s4=pd.Series([500,200,50,70])
d={'Pcd'':s1, 'title':s2, 'Price':s3, 'qty':s4}
lib=pd.DataFrame(d)
print(lib)
5 Pcd title Price qty 2
0 P01 Notebook 85 500
1 P02 Pencilbox 76 200
2 P03 WaterBottle 129 50
3 P04 SchoolBag 730 70
Transpose of DATAFRAME df
0 1 2 3
25 | P a g e
Pcd P01 P02 P03 P04
Title Notebook Pencilbox WaterBottle SchoolBag
Price 85 76 129 730
Qty 500 200 50 70
6 import pandas as pd 2
d=[[‘P01’,’Notebook’,85,500],[ ‘P02’,’Pencilbox’,76,200], [‘P03’,
‘WaterBottle’,129,50],[ ‘P04’,’SchoolBag’,730,70]]
c=['Pcd','title','Price','qty']
df=pd.DataFrame(d,columns=c)
import csv
df.to_csv(r"C:\Users\rasha\OneDrive\Desktop\sa.csv")
7 import pandas as pd 2
d=[['Delhi',40,32,24.1],['Bengaluru',31,25,36.2],['Chennai',35,27,40.
8],['Mumbai',29,21,35.2]]
c=['city','Maxtemp','Mintemp','Rainfall']
temp=pd.DataFrame(d,columns=c)
import csv
temp.to_csv(r"C:\Users\rasha\OneDrive\Desktop\temp.csv")
8 i. temp[‘ACC_NO ‘]=[135,153,225,442] 4
ii. temp.loc[4]=[‘p05’,’bigbook’,20,20]
iii. temp.drop([‘qty’],axis=1,inplace=True)
iv. temp.drop([0,2],axis=0,inplace=True)
9 i. df['E']=[14,220] 4
ii. df.loc[2]=[11,22,33,40,50]
iii. df.drop(['A','C'],axis=1,inplace=True)
iv. df.drop([0,1],axis=0,inplace=True)
10 print(df.T) 1
TOTAL
26 | P a g e
KENDRIYA VIDYALAYA SANGATHAN, AHEMDABAD REGION
CLASS XII – IP
NAME OF CHAPTER:Data Frame
TOPIC: max(),min(),sort_values(),sort_index(),sum() function of Data Frame and add
two DataFrame,rename index,rename columns and rename both index and columns
WORKSHEET NO. 7
QN Questions M
1 Consider the following dataframe: student_df [10x1]
Name CLASS marks
Anamay XI 95
Aditi XI 82
Mehak XI 65
Kriti XI 45
1. Write a statement to get the minimum value of the column
marks.
2. Write a statement to get the maximum value of the column
marks.
3. Write a statement to get the sum value of the column marks.
4. write a statement to get the average value of the column marks.
5. Write a statement to get Transpose of DataFrame student_df.
6. Write a statement to get the sorted value of the column marks.
7. Write a statement to get the sorted value of the column name
ascending.
8. Write a statement to get the sorted value of the column name
descending.
9. Write a statement to get the sort index of DataFrame.
10. Write a statement to get the sorted column index of
DataFrame.
2 Write the code in pandas to create the following DataFrames: [10x1]
df1 df2
mark1 mark2 mark1 mark2
0 10 15 0 30 20
1 40 45 1 20 25
2 15 30 2 20 30
3 40 70 4 40 10
5 10 50 3 50 30
Write the commands to do the following operations on the
DataFrames given above:
1.To add DataFrames df1 and df2.
2.To add 10 values into df1 DataFrame
3.To add 5 values into mark1 columns of DataFrame
4.To add DataFrame d1 into d2
d1 d2
mark1 mark2 mark1 mark2
0 10 15 0 30 20
1 40 45 1 20 25
2 15 30 2 20 30
3 40 70 4 40 10
5 10 50 3 50 30
5.To subtract df2 from df1
27 | P a g e
6.To rename column mark1 as m1 in df2.
7.To change index label of df1 from 0 to zero and from 1 to one
8.To rename column mark1 as m1, mark2 as m2 and row 0 to 00
and 1 to 01 of df2 DataFrame
9.To change the column heading of df1 to m11 for mark1 and m12
for mark2
10. Do for following
d1 d2
mark1 mark2 mark1 mark2
0 10 15 0 30 20
1 40 45 1 20 25
f1 f2
m1 m2 mark1 mark2
0 10 15 0 30 20
1 40 45 1 20 25
Print(d1[:2]+d2[:2])
Print(f1[:2]+f2[:2])
TOTAL 20
***
28 | P a g e
KENDRIYA VIDYALAYA SANGATHAN, AHEMDABAD REGION
CLASS XII – IP
NAME OF CHAPTER:Data Frame
TOPIC: max(),min(),sort_values(),sort_index(),sum() function of Data Frame and add
two DataFrame,rename index,rename columns and rename both index and columns
QN Answers M
1 Consider the following DataFrame: student_df 2
Name CLASS marks
Anamay XI 95
Aditi XI 82
Mehak XI 65
Kriti XI 45
1.Write a statement to get the minimum value of the column marks.
>>> student_df["marks"].min()
45
7.Write a statement to get the sorted value of the column name ascending.
29 | P a g e
student_df.sort_values(by=["Name"],ascending=True)
Name CLASS marks
1 Aditi XI 82
0 Anamay XI 95
3 Kriti XI 45
2 Mehak XI 65
8.Write a statement to get the sorted value of the column name descending.
student_df.sort_values(by=["Name"],ascending=False)
Name CLASS marks
2 Mehak XI 65
3 Kriti XI 45
0 Anamay XI 95
1 Aditi XI 82
30 | P a g e
0 15
1 45
2 20
3 45
Name: mark1, dtype: int64
4.d1 d2
mark1 mark2 mark1 mark2
0 10 15 0 30 20
1 40 45 1 20 25
2 15 30 2 20 30
3 40 70 4 40 10
5 10 50 3 50 30
To add DataFrame d1 into d2
d1+d2
mark1 mark2
0 40.0 35.0
1 60.0 70.0
2 35.0 60.0
3 90.0 100.0
4 NaN NaN
5 NaN NaN
>>>
df2-df1
mark1 mark2
0 20 5
1 -20 -20
2 5 0
3 10 -40
31 | P a g e
8 .To rename column mark1 as m1,mark2 as m2 and row 0 to 00 and 1 to 01
of df2 DataFrame
df2.rename(index={0:"00",1:"01"},columns={"mark1":"m1","mark2":"m2"}
)
m1 m2
00 30 20
01 20 25
2 20 30
3 40 10
4 50 30
9.To change the column heading of df1 to m11 for mark1 and m12 for mark2
df1.columns=["m11","m12"] # changes in original variable
>>> df1
m11 m12
0 30 20
1 20 25
2 20 30
3 40 10
4 50 30
10. 10.do for following
d1 d2
mark1 mark2 mark1 mark2
0 10 15 0 30 20
1 40 45 1 20 25
f1 f2
m1 m2 mark1 mark2
0 10 15 0 30 20
1 40 45 1 20 25
Print(d1[:2]+d2[:2])
Print(f1[:2]+f2[:2])
>>> d1[:2]+d2[:2]
mark1 mark2
0 40 35
1 60 70
>>> f1[:2]+f2[:2]
m1 m2 mark1 mark2
0 NaN NaN NaN NaN
1 NaN NaN NaN NaN
TOTAL
32 | P a g e
KENDRIYA VIDYALAYA SANGATHAN, AHEMDABAD REGION
CLASS XII – IP
NAME OF CHAPTER:Data Frame
TOPIC: max(),min(),sort_values(),sort_index(),sum() function of Data Frame and add
two DataFrame,rename index,rename columns and rename both index and columns:
WORKSHEET NO. 8
Q. Questions M
No
1 Create following batsman DataFrame using csv method [1x10]
Do following operation
1) Add score1 and score2 and assign it to column total
2) Display lowest score of score1.
3) Display highest score of score2
4) change index to player1,player2, player3,player4
5) Display all the details of DataFrame whose score1 <75
6) Display only name of DataFrame whose score1 <75
7) Display name and score1 of DataFrame whose score1 <75
8) Display DataFrame in descending order of score2
9) Change the column name to batsmanno,bname, s1 ,s2 and sum
of DataFrame
10)Add 5 score to those who have more than 75 score2
TOTAL 10
***
33 | P a g e
KENDRIYA VIDYALAYA SANGATHAN, AHEMDABAD REGION
CLASS XII – IP
NAME OF CHAPTER:Data Frame
TOPIC: max(),min(),sort_values(),sort_index(),sum() function of Data Frame and add
two DataFrame,rename index,rename columns and rename both index and
columns,filtering of DataFrame
>>> batsman["total"]=batsman["score1"]+batsman["score2"]
>>> batsman
Bno name score1 score2 total
0 1 Sunil Grover 90 80 170
1 2 sourav ganguli 65 45 110
2 3 virat kohli 70 90 160
3 4 Rahul dravid 80 70 150
34 | P a g e
player2 2 sourav Ganguli 65 45 110
player3 3 virat kohli 70 90 160
player4 4 Rahul dravid 80 70 150
>>> batsman[batsman["score1"]<75][["name","score1"]]
name score1
player2 sourav ganguli 65
player3 virat kohli 70
35 | P a g e
KENDRIYA VIDYALAYA SANGATHAN, AHEMDABAD REGION
CLASS XII – IP
NAME OF CHAPTER: DataFrame
TOPIC: Access row and column using loc and iloc method, access and change individual
element of data frame by at and iat
WORKSHEET NO. 9
QN Questions M
1 loc and iloc
Create DataFrame df using csv method and write python code as per direction
0 1 2 3
Product Company qty price
101 cpu compaq 40 9000
102 mouse compaq 20 400
103 keyboard dell 10 700
104 printer hp 2 20000
105 hdd sony 500 450
106 cd sony 1000 25
107 scanner hp 4 5500
108 speaker dell 6 900
1)Display all product except product no 101 and 102
2)Display all the product details of record no 102,104 and 106.
3)Display product and company details of all records of DataFrame
4)Display product and company details of 101 and 104 records of DataFrame
5)Display name of all products of DataFrame.
6)Display first record of DataFrame.
7)Display price of all product of DataFrame.
8)Display company name of all product of DataFrame.
9)Display quantity and company details of all records of DataFrame
10)Display the details of record no 104
2 0 1 2 3
Product Company qty price
101 cpu compaq 40 9000
102 mouse compaq 20 400
103 keyboard dell 10 700
104 printer hp 2 20000
105 hdd sony 500 450
106 cd sony 1000 25
107 scanner hp 4 5500
108 speaker dell 6 900
36 | P a g e
KENDRIYA VIDYALAYA SANGATHAN, AHEMDABAD REGION
CLASS XII – IP
NAME OF CHAPTER:DataFrame
TOPIC: Access row and column using loc and iloc method,access and change individual
element of DataFrame by at and iat
QN Answers M
1 import pandas as pd 2
>>>df=pd.read_csv(r"C:\Users\rasha\OneDrive\Desktop\comp.csv"
)
>>> df
df.index=["101","102","103","104","105","106","107","108"]
0 1 2 3
Product Company qty price
101 cpu compaq 40 9000
102 mouse compaq 20 400
103 keyboard dell 10 700
104 printer hp 2 20000
105 hdd sony 500 450
106 cd sony 1000 25
107 scanner hp 4 5500
108 speaker dell 6 900
>>> df[101:]
Empty DataFrame
Columns: [Product, Company, qty, price]
Index: []
1)Display all product except product no 101 and 102
df["103": ] or df.loc["103": ] or df.iloc[2: ]
df.loc[["102","104","106"]] or df.iloc[[1,3,5]]
Product Company qty price
102 mouse compaq 20 400
104 printer hp 2 20000
106 cd sony 1000 25
37 | P a g e
101 cpu compaq
102 mouse compaq
103 keyboard dell
104 printer hp
105 hdd sony
106 cd sony
107 scanner hp
108 speaker dell
df.loc[["101","104"],['Product','Company']]
or df.iloc[[0,3],[0,1]]
Product Company
101 cpu compaq
104 printer hp
38 | P a g e
104 hp
105 sony
106 sony
107 hp
108 dell
>>> df.loc["105"]=["plotter","sony",2,26000]
39 | P a g e
>>> df
Product Company qty price
101 cpu compaq 40 9000
102 mouse compaq 20 400
103 keyboard dell 10 700
104 printer hp 50 20000
105 plotter sony 2 26000
106 cd sony 1000 25
107 scanner hp 4 5500
108 speaker dell 6 900
109 mic dell 100 450
>>>
df.loc["101":"102",'Company':'qty']=[["intel",50],["samsung
",50]]
>>> df
Product Company qty price
101 cpu intel 50 9000
102 mouse samsung 50 400
40 | P a g e
103 keyboard dell 10 700
104 printer hp 50 20000
105 plotter sony 2 26000
106 cd sony 1000 25
107 scanner hp 4 5500
108 speaker dell 6 900
109 mic dell 100 450
TOTAL
***
41 | P a g e
KENDRIYA VIDYALAYA SANGATHAN, AHEMDABAD REGION
CLASS XII – IP
NAME OF CHAPTER:DataFrame
TOPIC: Access row and column using loc and iloc method,access and change individual
element of DataFrame by at and iat
WORKSHEET NO. 10
Q. Questions M
No
1 loc and iloc 1x10
Create DataFrame df using csv method and write python code as per
direction
0 1 2 3
name dept age salary
101 Heena sales 40 14000
102 Ayush Purchase 28 20400
103 diohm sales 30 37700
104 varshabh Purchase 25 20000
105 shubhi Purchase 22 45000
106 priyansh sales 21 10000
107 ankush IT 40 55000
108 samy IT 36 60900
42 | P a g e
KENDRIYA VIDYALAYA SANGATHAN, AHEMDABAD REGION
CLASS XII – IP
NAME OF CHAPTER: DataFrame
TOPIC: Access row and column using loc and iloc method, access and change individual
element of DataFrame by at and iat
QN Answers M
1 import pandas as pd 1x10
>>> df=pd.read_csv(r"C:\Users\rasha\OneDrive\Desktop\comp.csv")
>>> df
df.index=["101","102","103","104","105","106","107","108"]
df.loc[["102","104","106"]] or df.iloc[[1,3,5]]
name dept age salary
102 Ayush Purchase 28 20400
104 varshabh Purchase 25 20000
106 priyansh sales 21 10000
43 | P a g e
107 ankush IT
108 samy IT
4)Display employee name and salary details of 101 and 104 records of
DataFrame
df.loc[["101","104"],['name','salary']]
or df.iloc[[0,3],[0,1]]
name salary
101 Heena 14000
104 varshabh 20000
44 | P a g e
Name: name, dtype: object
name varshabh
dept Purchase
age 25
salary 20000
Name: 104, dtype: object
2 1)Display name of first record. 1x8
df.at["101",'name'] or df.iat[0,0]
40
45 | P a g e
107 ankush IT 40 55000
108 samy IT 36 60900
109 raksha comp 40 45000.
>>> df.loc["105"]=["subhi","sales",27,26000]
>>> df
name dept age salary
101 Heena sales 40 14000
102 Ayush Purchase 28 20400
103 diohm sales 30 37700
104 varshabh Purchase 25 50000
105 subhi sales 27 26000
106 priyansh sales 21 10000
107 ankush IT 40 55000
108 samy IT 36 60900
109 raksha comp 40 45000
7) Change the department name to comp and age to 30 of record no 101 and
102
df.loc["101":"102",'dept':'age']=["comp",30]
>>> df
name dept age salary
101 Heena comp 30 40000
102 Ayush comp 30 40000
103 diohm sales 30 37700
104 varshabh Purchase 25 50000
105 subhi sales 27 26000
106 priyansh sales 21 10000
107 ankush IT 40 55000
108 samy IT 36 60900
109 raksha comp 40 45000
8) change the dept and salary details of 101 and 102 record
As per given below
101 office 25 25050
46 | P a g e
102 comp 38 30050
>>>
df.loc["101":"102",'dept':'salary']=[["office",25,25050],["comp",38,30
050]]
>>> df
name dept age salary
101 Heena office 25 25050
102 Ayush comp 38 30050
103 diohm sales 30 37700
104 varshabh Purchase 25 50000
105 subhi sales 27 26000
106 priyansh sales 21 10000
107 ankush IT 40 55000
108 samy IT 36 60900
109 raksha comp 40 45000
TOTAL 18
47 | P a g e
KENDRIYA VIDYALAYA SANGATHAN, AHEMDABAD REGION
CLASS XII – IP
NAME OF CHAPTER: -CREATE DATA FRAME
TOPIC: Assertion & Reason
WORKSHEET NO. 11
QN Questions M
Directions: In the following questions, a statement of Assertion (A) is
followed by a statement of Reason (R). Mark the correct choice as:
(A) Both Assertion (A) and Reason (R) are true, and Reason (R) is the
correct explanation of Assertion (A).
(B) Both Assertion (A) and Reason (R) are true, but Reason (R) is not
the correct explanation of Assertion (A).
(C) Assertion (A) is true, but Reason (R) is false.
(D) Assertion (A) is false, but Reason (R) is true.
1 Q.1. Assertion (A): DataFrame is a two-dimensional labelled array. 1
Its columns types can be heterogeneous i.e., of varying types.
Reason (R): We need a DataFrame with a Boolean index to use the
Boolean indexing.
2 Assertion (A): Iteration is a general term for taking each item of 1
something one after another. Reason (R): itertuples () returns the
iterator yielding each index value along with a series containing the data
in each row.
3 Assertion (A): Indexing can also be known as sub selection. 1
Reason (R): Pandas DataFrame.loc attribute access group of rows and
columns by label(s) or a boolean array in the given DataFrame.
4 Assertion (A): To delete a column from Panda DataFrame, drop() method 1
is used. Reason (R): Columns are deleted by dropping columns with
index label.
5 Assertion (A): Rows can also be selected by passing integer location. 1
Reason (R): Integer location can be pass to the iloc[] method
6 Assertion (A): head() function returns first n rows from the object based 1
on position.
Reason (R): n is the selected number of rows whose default value is 3.
7 Assertion (A): List of dictionary can be passed to form a DataFrame. 1
Reason (R): Keys of dictionary are taken as row names by default.
8 Assertion (A): Indexing can also be known as sub selection. 1
Reason (R): Pandas DataFrame.loc attribute access group of rows and
columns by label(s) or a Boolean array in the given DataFrame.
9 Assertion (A): CSV files are available to open in any spreadsheet 1
program, including Google Sheets, Open Office, and Microsoft Excel.
Reason (R): Using a spreadsheet program can serve a user's needs
better since it has cells where data sorted in rows and columns.
10 Assertion (A):- While creating a DataFrame with a nested or 2D 1
dictionary, Python interprets the outer dict keys as the columns and the
inner keys as the row indices.
Reasoning (R):- A column can be deleted using remove command
TOTAL 10
***
48 | P a g e
KENDRIYA VIDYALAYA SANGATHAN, AHEMDABAD REGION
CLASS XII – IP
49 | P a g e
KENDRIYA VIDYALAYA SANGATHAN, AHEMDABAD REGION
CLASS XII :– INFORMATICS PRACTICES (065)
TOPIC :- DATA HANDLING USING PANDAS (UNIT – 1)
50 | P a g e
KENDRIYA VIDYALAYA SANGATHAN, AHEMDABAD REGION
CLASS XII :– INFORMATICS PRACTICES (065)
TOPIC :- DATA HANDLING USING PANDAS (UNIT – 1)
(i) print(S.iloc[1:3])
(ii) print(S.loc[‘B’ : ‘D’])
4. Consider a list L and a Series object S storing 3 values (10, 20 and 30). What will be
the output of the following statements.
(i) L*2
(ii) S*2
5. Find the output of the following code:
import pandas as pd
S = pd.Series(10, index = [‘a’, ‘b’, ‘c’])
print(S.size)
print(S.ndim)
print(S.hasnans)
6. Find the output of the following code:
import pandas as pd
x = (10,4)
S = pd.Series(data = x*2)
print(S)
51 | P a g e
KENDRIYA VIDYALAYA SANGATHAN, AHEMDABAD REGION
CLASS XII :– INFORMATICS PRACTICES (065)
TOPIC :- DATA HANDLING USING PANDAS (UNIT – 1)
52 | P a g e
9. Write a statement to transpose a dataframe df.
KENDRIYA VIDYALAYA SANGATHAN, AHEMDABAD REGION
CLASS XII :– INFORMATICS PRACTICES (065)
TOPIC :- DATA HANDLING USING PANDAS (UNIT – 1)
53 | P a g e
print(df2)
KENDRIYA VIDYALAYA SANGATHAN, AHEMDABAD REGION
CLASS XII :– INFORMATICS PRACTICES (065)
TOPIC :- DATA HANDLING USING PANDAS (UNIT – 1)
1. A Python list namely section stores the section names (‘A’, ‘B’, ‘C’, ‘D’) of class 12 in
your school. Another list contri stores the contribution made by these students to a
charity fund endorsed by the school. Write code to create a Series object that stores the
contribution amount as the values and the section names as the indexes.
2. While reading from a csv file using read_csv() into a dataframe, what argument will
you add so that the first row is not used as the column heading?
3. You want to read data from a CSV file in a dataframe but you want to provide your
own column names to dataframe. What additional argument would you specify in
read_csv()?
4. While reading from a csv file using read_csv() into a dataframe, what argument will
you add so that the top n number of rows are not read into the dataframe?
5. Which argument would you give to read_csv() if you want to read top 10 rows of
data only?
6. Write statement to read from a CSV file Employee.csv and create a dataframe from
it. Assume pandas library has been imported as pd.
7. Write a statement to read only three records from the file employee.csv in
dataframe. Assume that Pandas library has been imported as pd.
8. Write statement to read from sport.csv file where the separator is a tab character.
Assume that pandas library has been imported as pd.
9. Given a dataframe allDF. Write a statement to write the data in this dataframe into a
csv file namely all.csv. Assume that pandas library has been imported as pd.
10. Write command to store data of dataframe mdf into a csv file Mydata.csv, with
separator character as ‘@’.
54 | P a g e
KENDRIYA VIDYALAYA SANGATHAN, AHEMDABAD REGION
CLASS XII :– INFORMATICS PRACTICES (065)
TOPIC :- DATA HANDLING USING PANDAS (UNIT – 1)
8. Name two functions provided by Pandas library that help you to read and write to
CSV files from Python code.
9. Which Pandas’ data structure does the read_csv() function read the data into?
55 | P a g e
KENDRIYA VIDYALAYA SANGATHAN, AHEMDABAD REGION
CLASS XII :– INFORMATICS PRACTICES (065)
TOPIC :- DATA HANDLING USING PANDAS (UNIT – 1)
(a) Write the command which will display the names of the furniture having rent >
250
(b) Write command to name the series as Furniture.
5. Write a program to create a Series object with 6 random integers and having
indexes as: [‘p’, ‘q’, ‘r’, ‘s’, ‘t’, ‘v’].
6. A dataframe namely Result stores the details of students’ marks in different subjects
for a class of 50 students. The records are arranged in the descending order of total
marks obtained by a student:
Eng IP Maths
23 77 78 78
11 82 85 67
22 55 66 66
34 66 76 73
9 78 60 44
: : : :
(i) Write a statement to print the five least scoring students’ details.
(ii) Write a statement to get the maximum marks stored in subject IP.
(iii) Write a statement to print the details of the student who scored maximum marks in
the subject Eng.
(iv) Write a statement to print the three highest scoring students.
(v) Write a statement to display the marks scored by a student with roll number 22, in
the subject Math.
56 | P a g e
KENDRIYA VIDYALAYA SANGATHAN, AHEMDABAD REGION
CLASS XII :– INFORMATICS PRACTICES (065)
TOPIC :- DATA HANDLING USING PANDAS (UNIT – 1)
1. The python code written below has syntactical errors. Rewrite the correct code
and underline the corrections made.
import Pandas as pd
Import numpy as np
s = pd.Series [1, 2, 3, 4, 5 ]
Print(s.index)
2. The python code written below has syntactical errors. Rewrite the correct code
and underline the corrections made.
import pandas as pd
S1 = Pd.Series([1,2,3,4])
S2 = pd.Series([5,6,7,8])
df = pd.Dataframe(s1,s2)
Print(DF)
(i) statement 1: fill the blank to give column heading as ‘C1’, ‘C2’ and ‘C3’.
(ii) statement 2: fill statement that creates dataframe n1 that stores the values of
dataframe df multiplied by 3.
(iii) statement 3: fill statement that adds a new column ‘C4’ in the dataframe n1,
which stores the difference of column ‘C3’ with column ‘C2’.
(iv) statement 4: fill statement to drop column ‘C4’.
(v) statement 5: fill statement to drop the index 2 from dataframe n1.
(vi) statement 6: fill statement to display the sum of rows with indexes 2 onwards
from the dataframe df.
57 | P a g e
Answers(Worksheet 12):
1. ndim
2. size
3. nbytes
5. value, size
7.
A 21.0
B 34.0
C NaN
D 53.0
P NaN
dtype: float64
8. (i) print(S[2])
(ii) print(S[-3:])
(iii) print(S[:5])
9 b 6
a 5
dtype: int64
10 import pandas as pd
S = pd.Series([76.6, 48.8, 96.8, 85.0, 78.2, 77.6, 92.8, 88.2, 66.8, 81.4], index
= [‘A’, ‘B’, ‘C’, ‘D’, ‘E’, ‘F’, ‘G’,’ H’, ‘I’, ‘J’]
print(S.sort_values().tail(1))
58 | P a g e
Answers(Worksheet 13):
1. S[[2, 5, 7]] = 50
2. (i) 0 37 (ii) 0 True (iii) 0 34
1 -4 1 False 2 20
2 23 2 True 3 4
3 7 3 True dtype: int64
dtype : int64 dtype: bool
3. (i) B 20 (ii) B 20
C 30 C 30
dtype: int64 D 40
dtype:int64
4. L*2 = [10, 20, 30, 10, 20, 30]
S*2 = 0 20
1 40
2 60
dtype: int64
5. 3
1
False
6. 0 10
1 4
2 10
3 4
dtype: int64
59 | P a g e
Answers(Worksheet 14)
1. (a) rows
2. df.iat[3,5] = 50
3. (i) A, B, Q1, Q2, Q4, Qtr3, Qtr4
(ii) 1, 2
4. (i) print(aid[[‘Books’, ‘Uniform’]])
(ii) print(aid.Shoes)
(iii) print(aid.loc[‘Andhra’:’Odisha’, ‘Books’:’Uniform’])
5. aid[‘Bread’] = [1245, 956, 1546, 933]
6. (i)
A B C
0 10 11 NaN
1 25 26 NaN
2 51 52 NaN
(ii) Error, because the number of values being assigned are not equal to the number of
indexes.
(iii)
A B C
0 10 11 4
1 25 26 5
2 51 52 6
7. df.drop[‘Sales’]
8. df.iloc[4,5] = 100
9. df.T
60 | P a g e
Answers(Worksheet 15)
1. (A)
(a)df[‘col3’] or df.loc[ : , ‘col3’]
(b) df.loc[‘t3’, : ]
(c) df.loc[‘t2’, ‘col2’]
(d) df.loc[‘t4’, ‘col2’ : ‘Res’]
(e) df.drop([‘t2’, ‘t3’])
(f) df.drop([‘col2’, ‘Res’], axis = 1)
(B)
(a) False 60.0
(b) 49.2 False
(c)
col1 col2 col3 Res
t2 95.8 100.0 57.48 True
t3 89.3 100.0 53.58 False
t4 82.0 85.4 49.20 False
(d)
col3 Res
t1 60.00 True
t2 57.48 True
t3 53.58 False
t4 49.20 False
(e)
col3 Res
t2 57.48 True
t3 53.58 False
(f)
col3 Res
t1 60.00 True
t2 57.48 True
(g)
col1 col2 col3
t3 89.3 100.0 53.58
t4 82.0 85.4 49.20
(h)
col3
t2 57.48
t3 53.58
2.
PID PNAME
61 | P a g e
A P01 Pen
B P02 Pencil
C P03 Eraser
3. import pandas as pd
df = pd.DataFrame([[1,2], [3, 4],[5, 6], [7, 8]], columns = [‘a’, ‘b’])
print(df)
4.
one two
a 1.0 1.0
b 2.0 2.0
c 3.0 3.0
d NaN 4.0
one two
d NaN 4.0
b 2.0 2.0
a 1.0 1.0
two three
d 4.0 NaN
a 1.0 NaN
62 | P a g e
Answers(Worksheet 16):
1. import pandas as pd
section = [‘A’, ‘B’, ‘C’, ‘D’]
contri = [6500, 4500, 5000, 5600]
s = pd.Series(contri, index = section)
print(s)
2. To suppress first row as header, the additional argument will be:
header = None
3. To specify own column names, the additional argument will be:
name = <sequence with column names>
4. To skip top n rows, the additional argument will be:
skiprows = n
5. To read top 10 rows from a csv file, the additional argument will be:
nrows = 10
6. df = pd.read_csv(“Employee.csv”)
7. df = pd.read_csv(‘employee.csv’, nrows = 3)
8. df = pd.read_csv(“sport.csv”, sep = ‘\t’)
9. allDF.to_csv(“all.csv”)
10. mdf.to_csv(“Mydata.csv”, sep = “@”)
63 | P a g e
Answers(Worksheet 17):
1. The acronym CSV is short for Comma-Separated Values, which refers to a tabular
data saved as plaintext where data values are separated by commas.
2. import pandas as pd
df = pd.read_csv(‘data.csv’, sep = ‘$’, names = [‘ItemName’, ‘Quantity’, ‘Price’],
header = None, nrows = 5)
print(df)
3. import pandas as pd
df = pd.read_csv(‘Employee.csv’, header = None, skiprows = 1)
print(df)
4. import pandas as pd
df = pd.read_csv(“Employee.csv”, index_col = ‘Empno’)
print(df)
5. Yes, both the given statements will work identically even if thie code is slightly
different. The reason being – in that first statement the sep argument is used, which
specifies the separator character or the delimeter of the csv files being read. Here the
value of sep argument is given as ‘,’.
Even if we skip the sep argument, it takes its value as ‘,’ by default, which is happening
in the second case.
Hence both the statements will behave in the same way even with their slight code
difference.
6. The two given code fragments are different from one another as:
The code (i) will read only the first 5 rows from the file data.csv into the dataframe df
whereas the code (ii) will read all the data data stored in the file data.csv and store it in
the dataframe df.
7. import pandas as pd
df = pd.read_csv(“C:\\marks.csv”, names = [“Name”, “Marks1”, “Marks2”,
“Marks3”] )
print(“Dataframe after fetching data from CSV file:”)
print(df)
df[‘Total’] = df[‘Marks1’] + df[‘Marks2’] + df[‘Marks3’]
df[‘AvgMarks’] = df[‘Total’]/3
print(“Dataframe after all the calculations”
print(df)
8. read_csv() fro reading from a csv file and to_csv() for writing onto a csv file.
9. DataFrame
64 | P a g e
Answers(Worksheet 18):
1.
Series DataFrame
A Series is a one-dimensional data A Dataframe is a two-dimensional data
structure. structure
A Series object is value mutable but not A Dataframe object is value as well as
size mutable. size mutable both
Multiple Series can hold the same data as A Dataframe can hold the data of multiple
a dataframe but ease of operation is lost. series under one name and hence ease of
operation
2. A Dataframe having a single column may look same as a Series but there is a key
difference. As both the Series and the dataframe data structure are value mutable, but
dataframe is size mutable while series is size immutable. Thus, even though the series
object and a dataframe object with single column appear the same, they behave
differently when thir size is changed.
3. (a) This statement will create a dataframe df2 as a shallow copy and not as a True
copy of the dataframe df1. That is, just another label by the name df2 has been created
for the dataframe df1. Hence all the changes made to df1 will be reflected in df2 and
vice-versa.
(b) This statement will create a dataframe df3 as a True copy of the dataframe df1,
because of the argument copy = True. That is, df1 and df3 are two separate entities
now and changes in df1 will not affect df3 and vice-versa.
5. import pandas as pd
import numpy as np
s = pd.Series(np.random.randint(6, size = 6), index = [‘p’, ‘q’, ‘r’, ‘s’, ‘t’, ‘v’])
print(s)
6.
(i) Result.tail() or Result.tail(5)
(ii) Result[‘IP’].max()
(iii) Result[Result[‘Eng’] = = Result[‘Eng’].max()]
(iv) Result.head(3)
(v) Result.at[22, ‘Math’]
65 | P a g e
Answers(Worksheet 19):
1. import pandas as pd
import numpy as np
s = pd.Series ( [1, 2, 3, 4, 5 ] )
print(s.index)
2. import pandas as pd
S1 = pd.Series([1,2,3,4])
S2 = pd.Series([5,6,7,8])
df = pd.DataFrame([S1,S2])
print(df)
66 | P a g e
KENDRIYA VIDYALAYA SANGATHAN, AHEMDABAD REGION
CLASS XII :– INFORMATICS PRACTICES (065)
TOPIC :- DATA VISUALISATION (UNIT – 1)
67 | P a g e
20. You can set different width for different bars in bar chart. (True/False)
21 If you are given to plot a histogram using numpy array as per the code given below
then answer any of four question from (i) to (v)
(v) To fill in blank on Line 10 for showing histogram what can beeused ?
(a) plt.show() (b) plt_show()
(c) plot_show() (d) plt.show
************
68 | P a g e
KENDRIYA VIDYALAYA SANGATHAN, AHEMDABAD REGION
CLASS XII :– INFORMATICS PRACTICES (065)
TOPIC :- DATA VISUALISATION (UNIT – 1)
WORKSHEET - 2
69 | P a g e
B. Bar chart
C. Pie chart
D. Scatter plot
9. Which method is used to plot horizontal bar graph in pyplot ?
A. horizontal_bar()
B. barh()
C. hbar()
D. bar()
10. Which method is used to plot histogram in pyplot?
A. his()
B. hist()
C. Hist()
D.histogram()
11. Consider the following program and answer any four question from (i) to
(v):
import _______ as plt #line 1
plt.bar ([2,3,4,8,1],[2,4,7,3,5], label= _____ ) #line 2
plt.legend( ) #line 3
plt.xlabel(____ ) #line 4
plt.ylabel(‘Height’) #line 5
plt._______ (‘Vertical Bar Chart’) #line 6
________________ #line 7
(ii) Name the label that can be used to represent the bar chart in Line 2 .
a) Data (b) Data Values
b) Values for X axix (d) All of these
(iv) Which method will take place at Line 6 for setting heading on the top of Chart ?
(a) Title() (b) title()
(c) Head() (d) All of these.
12. Consider the following case and answer the from (i) to (v)
70 | P a g e
import …………. as pd #line 1
import matplotlib. _____ as plt #line 2
data= {‘Name’ : [‘Karan’, ‘Adi’, ‘Abhinav’, ‘Kirti’, ‘Rahul’ ],
‘Height’ : [60,61,63,65,61],
‘Weight’ : [47,89,52,58,50,47]}
df=pd. _________ (data) #line 6
df._____ (Kind =’hist’, edgecolor = ‘Green’, linewidth =2, linestyle=’:’ , fill= False)
#line 7
_____________ #line 8
13. Mr. Vijay is working in the mobile app development industry and he was
comparing the given chart on the basis of the rating of the various apps available
on the play store and answer the questions (i) to (v).
71 | P a g e
He is trying to write a code to plot the graph. Help Mr. Vijay to fill in the blanks of the
code and get the desired output.
plt.__________(apps,ps_rating,color='m',label=__________) #Statement 2
,Statement 3
plt.xlabel("Apps")
plt._____________("Rating") #Statement 4
plt._________ #Statement 5
plt.________ #Statement 6
************
72 | P a g e
KENDRIYA VIDYALAYA SANGATHAN, AHEMDABAD REGION
CLASS XII :– INFORMATICS PRACTICES (065)
TOPIC :- DATA VISUALISATION (UNIT – 1)
WORKSHEET - 3
**************
73 | P a g e
KENDRIYA VIDYALAYA SANGATHAN, AHEMDABAD REGION
CLASS XII :– INFORMATICS PRACTICES (065)
TOPIC :- DATA VISUALISATION (UNIT – 1)
WORKSHEET - 4
2. Collect data about colleges in Delhi University or any other university of your choice
and number of courses they run for Science, Commerce and Humanities, store it in a
CSV file and present it using a bar plot.
3. Collect the minimum and maximum temperature of your city for a month and present
it using a histogram plot.
4. Plot the following data on line chart:
Runs in Overs 10 20
MI 110 224
RCB 85 210
5. Write code to plot a line chart to depict the run rate of T20 match from given data:
Overs Runs
5 45
10 79
15 145
20 234
7. How to change the thickness of line, line style, line color, and marker properties of
a chart?
74 | P a g e
8. Mrs. Sharma is a coordinator in the senior section school. She represented data on
number of students who passed the exam on line chart as follows:
She has written the following code but not getting the desired output. Help her
by correcting her code.
*************
75 | P a g e
KENDRIYA VIDYALAYA SANGATHAN, AHEMDABAD REGION
CLASS XII :– INFORMATICS PRACTICES (065)
TOPIC :- DATA VISUALISATION (UNIT – 1)
WORKSHEET - 5
1. Consider that a survey has to be done on how much distance the following vehicles have
covered in a span of five days. The data collected can be plotted in different plotting methods.
plot the data using Line plot:
BIKES
DAYS DISTANCE COVERED IN KMS
ENFIELD HONDA YAHAMA KTM
DAY 1 50 80 70 80
DAY 2 40 20 20 20
DAY 3 70 20 60 20
DAY 4 80 50 40 50
DAY 5 20 60 60 60
2. Consider question No.9 and plot the data using Bar Chart.
3. Consider question No.9 and plot the data using Pie Plot.
4. Consider question No.9 and plot the data using Scatter Plot.
5. Consider question No.9 and plot the data using Histogram Plot.
6. Write a Python program to draw line charts from the given financial data of ABC Co.
for 5 days in the form a DataFrame namely fdf as shown below :
Day1 Day2 Day3 Day4 Day5
0 74.25 56.03 59.30 69.00 89.65
1 76.06 68.71 72.07 78.47 79.65
2 69.50 62.89 77.65 65.53 80.75
3 72.55 56.42 66.46 76.85 85.08
7. Write a program to create a horizontal bar chart for India's medal tally.
Australia 80 59 59 198
England 45 45 46 136
India 26 20 20 66
Canada 15 40 27 82
8. Write a python code to draw the following bar graph representing the total sales in
each quarter. Add the title, label for X-axis, Y-axis. Use the following data for
plotting the graph.
76 | P a g e
Sales = [450,300,500,850]
Qtr = [“Qtr1”, “Qtr2”, “Qtr3”,”Qtr4”]
77 | P a g e
KENDRIYA VIDYALAYA SANGATHAN, AHEMDABAD REGION
CLASS XII :– INFORMATICS PRACTICES (065) 2023-24
1. a) line
2. a) title()
3. barh())
4. Matplotlib library
5. c) line()
6. b) savefig
7. d) histogram
8. c) hist()
9. What is the purpose of a legend?
10. pyplot
11. matplotlib
12. line
13. True
14. a) plot()
15. b) pl.xlabel(“title”)
16. True
17. c) pl.plot
18. True
19. c)
20. True
21. (c) pyplot
(a) subplots
(b) set_title
(d) set_ylabel
plt.show()
************
78 | P a g e
KENDRIYA VIDYALAYA SANGATHAN, AHEMDABAD REGION
INFORMATICS PRACTICES (065) CLASS : XII
UNIT – 1
TOPIC: DATA VISUALISATION
79 | P a g e
KENDRIYA VIDYALAYA SANGATHAN, AHEMDABAD REGION
INFORMATICS PRACTICES (065) CLASS : XII
UNIT – 1
TOPIC: DATA VISUALISATION
WORKSHEET – 3 (Answer Key)
o savefig()
4. Write short notes on different customization options available with any plot.
Answer:
Answer:
80 | P a g e
o Legend represents the data displayed in the graph’s Y-axis.
o It helps to understand what the colors and shapes in the graph mean in
terms of data.
Answer:
Answer:
o To displays the statistical summary you can use bar plot and histogram.
10. What do you understand by x limit and ylimit ? How are theses linked to data
being plotted?
Answer:
xlimit and ylimit are used to set limit on the x & y axis range on which the data being
plotted is shown. xlim() &ylim() functions are used for this.e.g.
plt.xlim(-2.0,4.0)
The data on the chart will now be plotted only for the range from -2 to 4.
11. When should you use (i) a line chart (ii) a bar chart (iii)a pie chart?
Answer:
i)line chart
Line charts should be used when we need to connect all the data points and see
patterns.
ii)bar chart
Bar charts should be used when we need to visualize categorical data. It helps to
see trends.
iii)Pie chart
81 | P a g e
A pie chart shows how some total amount is divided among distinct categories as a
circle (the namesake pie) divided into radial slices. Each category is associated with
a single slice whose size corresponds with the category’s proportion of the total.
Answer:
(a) A bar Graph.
(b) In this a direct compare of the all quarter for various company will be done
easily.
(c) Yes, we can have three pie charts each for the different city branch.
82 | P a g e
KENDRIYA VIDYALAYA SANGATHAN, AHEMDABAD REGION
INFORMATICS PRACTICES (065) CLASS: XII
UNIT – 1
TOPIC: DATA VISUALISATION
Day 1 2 3 4 5 6 7
Tickets
2000 2800 3000 2500 2300 2500 1000
Sold
3. Collect the minimum and maximum temperature of your city for a month
and present it using a histogram plot.
83 | P a g e
Ans:
import pandas as pd
import matplotlib.pyplot as plt
min_temp=[6,5,6,5,5,5,4,9,11,12,14,15,12,13,11,11,8,7,10,10,9,9,7,8,9,5,6,6,7,10]
max_temp=[16,15,15,16,18,19,15,14,18,27,17,20,17,18,15,16,14,17,20,17,18,15,16]
plt.hist(min_temp,bins=5,color="brown",edgecolor="black")
plt.title("Minimum Temperatures in city During Fenruary 2021")
plt.ylabel("Frequency")
plt.xlabel("Temperature")
plt.show()
MI 110 224
RCB 85 210
Ans:
import matplotlib.pyplot as mpp
overs = [10,20]
mi = [110,224]
mpp.plot(overs,mi,'blue')
rcb=[109,210]
mpp.plot(overs,rcb,'red')
mpp.xlabel('Runs')
mpp.ylabel('Overs')
mpp.title('Match Summary')
mpp.show()
5. Write code to plot a line chart to depict the run rate of T20 match from given data:
Overs Runs
5 45
10 79
15 145
20 234
84 | P a g e
6. Plot following data on bar graph:
English: 56,78,90,34
Science: 65,77,54,32
Maths: 45,67,43,41
Ans:
import matplotlib.pyplot as pp
eng = [56,78,90,34]
sci = [65,77,54,32]
maths=[45,67,43,41]
pp.bar(eng,sci,maths)
pp.xlabel('Marks')
pp.ylabel('Subjects')
pp.show()
7. How to change the thickness of line, line style, line color, and marker
properties of a chart?
To change the thickness of line, use the linewidth parameter inside
matplotlib.pyplot.plot() function with a numeric value. For ex.:
pp.plot(x,y,linewidth=2)
She has written the following code but not getting the desired output. Help her by
correcting her code.
import matplotlib.pyplot as plt
CLASSes=["X A","X B","XI A","XI B","XII A","XII B"]
no_of_boys=[23,22,20,26,33,30]
no_of_girls=[17,10,20,12,5,8]
plt.line(CLASSes,no_of_boys) #Statement 1
plt.line(CLASSes,no_of_girls) #Statement 2
plt.xtitle("No of Stduents") #Statement 3
plt.ytitle("CLASSes") #Statement 4
plt.show()
85 | P a g e
vi. How to apply the line colours as given in the figure?
vii. Write to save the figure as image.
Ans.:
i) The code for statement 1 and statement 2 is as follows:
1. Statement 1: plt.plot(CLASSes,no_of_boys)
2. Statement 2:plt.plot(CLASSes,no_of_girls)
ii) The correct code for statement 3 and statement 4 is as follows:
1. plt.xlabel(‘CLASSes’)
2. plt.ylabel(‘No of stduents’)
iii) To display the legend she need to add label parameter in the plot method as
following:
1. plt.plot(CLASSes,no_of_boys,label=’Boys’)
2. plt.plot(CLASSes,no_of_girls,label=’Girls’)
To display legend she need to write this function: plt.legend()
iv) To apply the marker as given in the figure she needs to write the code as follows:
plt.plot(CLASSes,no_of_boys,marker='D')
plt.plot(CLASSes,no_of_girls,marker='o')
v) To apply the lines styles she needs to use a parameter linestyle or ls with the
values ‘dashed’ and ‘dotted’ respectively as follows:
plt.plot(CLASSes,no_of_boys,ls='dashed')
plt.plot(CLASSes,no_of_girls,ls='dotted')
vii) To save the figure as image she needs to use savefig() method as follows:
plt.savefig('boygirlspass.jpg')
86 | P a g e
KENDRIYA VIDYALAYA SANGATHAN, AHEMDABAD REGION
INFORMATICS PRACTICES (065) CLASS: XII
UNIT – 1
TOPIC: DATA VISUALISATION
1. Consider that a survey has to be done on how much distance the following vehicles
have covered in a span of five days. The data collected can be plotted in different
plotting methods.
BIKES
DISTANCE COVERED IN KMS
DAYS
ENFIELD HONDA YAHAMA KTM
DAY 1 50 80 70 80
DAY 2 40 20 20 20
DAY 3 70 20 60 20
DAY 4 80 50 40 50
DAY 5 20 60 60 60
87 | P a g e
2. Consider question No.9 and plot the data using Bar Chart.
88 | P a g e
3. Consider question No.9 and plot the data using Pie Plot.
4. Consider question No.9 and plot the data using Scatter Plot.
89 | P a g e
Y3=[70, 20, 60, 40, 60]
Y4=[80, 20, 20, 50, 60]
plt.scatter(days,Y1, label=’Enfield’,color=’r’)
plt.scatter(days,Y2,label=’Honda’,color=’b’)
plt.scatter(days,Y3,label=’Yahama’,color=’y’)
plt.scatter(days,Y4,label=’KTM’,color=’k’)
plt.xlabel(‘Days’)
plt.ylabel(‘Distance in kms’)
plt.title(‘ Bike details in Scatter Plot’)
plt.legend()
plt.show()
5. Consider question No.9 and plot the data using Histogram Plot.
The plotting of numerical data in a precise manner by using rectangular blocks forms the
basis of histogram plotting. A probability distribution can be estimated using a histogram
plot. The data is mostly represented in a continuous manner based on the data set
provided to plot the graph.
90 | P a g e
6. Write a Python program to draw line charts from the given financial data of ABC Co.
for 5 days in the form a DataFrame namely fdf as shown below :
Output:
91 | P a g e
7. Write a program to create a horizontal bar chart for India's medal tally.
Country Gold Silver Bronze Total
Australia 80 59 59 198
England 45 45 46 136
India 26 20 20 66
Canada 15 40 27 82
Answer:
import matplotlib.pyplot as plt
Info = ['Gold', 'Silver', 'Bronze', 'Total']
India = [26, 20, 20, 66]
plt.ylabel("Medal type")
plt.xlabel("Medal count")
plt.title("India's Medal Tally in Commonwealth 2018")
X = range (len (Info))
plt.barh(X, India, color = ['gold', 'silver', 'brown', 'black'])
plt.show()
Output:
*********
92 | P a g e
KENDRIYA VIDYALAYA SANGATHAN, AHEMDABAD REGION
NAME OF CHAPTER/ TOPIC: DATABASE QUERY USING SQL
WORKSHEET NO.:1 (Questions) ::CLASS XII – IP
93 | P a g e
a. Write SQL query to print records in descending order of year
of admission.
b. Write SQL query to display house and number of students in
each house.
c. Write SQL query to display CLASS wise highest fees.
d. Predict output.
SELECT LENGTH(SNAME) FROM STUDENT;
TOTAL 25
94 | P a g e
KENDRIYA VIDYALAYA SANGATHAN, AHEMDABAD REGION
NAME OF CHAPTER/ TOPIC: DATABASE QUERY USING SQL
WORKSHEET NO.:1 (Answers) ::CLASS XII – IP
QN Answers M
1 d) Aggregate function 1
2 a)Now() 1
3 c)Instr() 1
4 GROUP BY clause is used in a SELECT statement in conjunction with 2
aggregate functions to group the result based on distinct values in a
column.
5 Function is a special type of predefined command set that performs 2
some operations and returns a single value.
Types of functions:
i) Single row functions
a) Mathematical/Numeric function
b) String functions
c) Date and Time Functions
ii) Multiple row functions
6 Order by clause is used to sort data in ascending or descending order 2
based on one or more column.
Group by clause can be used in a SELECT statement to collect data
across multiple records and group the result by one or more columns.
7 WHERE clause works in respect to the whole table but HAVING 2
clause works on Group only.
If where and having both are used then where can be executed
first.
Where is used to put a condition on individual row of a table
whereas HAVING is used to put a condition on an individual group
formatted by GROUP BY clause in select statement.
Having clause support aggregate functions
8 Aggregate function is a function where the values of multiple rows are 2
grouped together as input based on a certain criterion to form a single
value of more significant meaning.
Different aggregate functions are : SUM(), AVG(), MAX(), MIN(),
COUNT()
9 I. 8 3
II. NO OUTPUT
III. 0
15
10 i. SELECT * FROM STUDENT ORDER BY ADMYEAR DESC; 4
ii. SELECT HOUSE, COUNT(HOUSE) FROM STUDENT GROUP BY
HOUSE;
iii. SELECT CLASS, MAX(FEES) FROM STUDENT GROUP BY CLASS;
iv.
LENGTH(SNAME)
4
5
5
5
5
95 | P a g e
4
5
5
11 i. SELECT MID(‘INDIA SHINING’,7,7); 5
ii. SELECT INSTR(‘WELCOME WORLD’,’COME’);
iii. SELECT ROUND(23.78,1);
iv. SELECT MOD(100,9);
v. SELECT TRIM(USERID) FROM USERS;
TOTAL 25
96 | P a g e
KENDRIYA VIDYALAYA SANGATHAN, AHEMDABAD REGION
NAME OF CHAPTER/ TOPIC: DATABASE QUERY USING SQL
WORKSHEET NO.:2 (Questions) ::CLASS XII – IP
97 | P a g e
iii) SELECT UPPER (MID("start up india",10));
10 Shreya, a database administrator has designed a database for a 4
clothing shop. Help her by writing answers of the following questions
based on the given table:
TABLE : CLOTH
CCODE CNAME SIZE COLOUR PRICE DOP
C001 JEANS XL BLUE 990 2022-01-21
C002 T SHIRT M RED 599 2021-12-12
C003 TROUSER M GREY 399 2021-11-10
C004 SAREE FREE GREEN 1299 2019-11-12
C005 KURTI L WHITE 399 2021-12-07
i. Write a query to display cloth names in lower case. (1)
ii. Write a query to display the lowest price of the cloths.(1)
iii. Write a query to count total number of cloths purchased of
medium size.
iv. Write a query to count year wise total number of cloths
purchased.
11 Write suitable SQL query for the following: 5
i. Display name of the Month from your date of birth.
ii. Convert email-id to lowercase.
iii. Count the number of characters in your name.
iv. To remove leading spaces from the ‘ VANDE BHARAT ‘.
v. Display the string ‘CHEST’ from the string ‘MANCHESTER
UNITED’.
TOTAL 25
98 | P a g e
KENDRIYA VIDYALAYA SANGATHAN, AHEMDABAD REGION
NAME OF CHAPTER/ TOPIC: DATABASE QUERY USING SQL
WORKSHEET NO.:2 (Answers) ::CLASS XII – IP
QN Answers M
1 iii) None value 1
2 ii) 10 1
3 d. Group by 1
4 The function COUNT(column_name) counts the number of records in 2
a particular column but not includes null value
While COUNT(*) will count total no of rows in a table , null value
doesn’t affect the result.
5 i. 125 2
ii. 2
6 i) 8.720 2
ii) 10
7 i) 2001 2
ii) Melinda
8 POW() – return the value m raise to power n, Type of mathematical 2
function
SUM() – return the sum of all the values of a given column,
aggregate function
9 i) "ALL THE BEST" 3
ii) INFOR
iii) INDIA
10 i. Select lower(CNAME) from cloth; 4
ii. Select min(price) from cloth;
iii. SELECT COUNT(*) FROM CLOTH GROUP BY SIZE HAVING
SIZE=’M’;
iv. SELECT YEAR(DOP) , COUNT(*) FROM CLOTH GROUP BY
YEAR(DOP);
11 i. SELECT MONTHNAME(‘2022-10-12’); 5
ii. SELECT LOWER(‘[email protected]’);
iii. SELECT COUNT(‘ROMIL’);
iv. SELECT LTRIM(‘ VANDE BHARAT ‘);
v. SELECT MID(‘MANCHESTER UNITED’, 4,5);
TOTAL 25
99 | P a g e
KENDRIYA VIDYALAYA SANGATHAN, AHEMDABAD REGION
NAME OF CHAPTER/ TOPIC: DATABASE QUERY USING SQL
WORKSHEET NO.:3 (Questions) ::CLASS XII – IP
QN Question M
1 The …… function works with data of multiple rows at a time and returns 1
aggregate value.
a. SUM()
b. AVG()
c. MAX()
d. COUNT()
2 The ……. Clause arrange the result set in the order of single column, 1
multiple columns and custom sort order too.
a. HAVING
b. GROUP BY
c. ORDER BY
d. DISTINCT
3 Which clause is used in query to place the condition on group in clause. 1
a. WHERE
b. HAVING
c. GROUP BY
d. Both (a) and (b)
4 Give output of the following queries as per given table: 2
Table: Interior
NO ITEMNAME TYPE DATEOFSTOCK PRICE DISCOUNT
1 RED ROSE DOUBLE BED 2022-02-23 32000 15
2 SOFT TOUCH BABY COT 2020-01-22 9000 10
3 ROUGH WOOD BABY COT 2021-02-15 8500 10
4COMFORT ZONE OFFICE TABLE 2020-09-27 20000 20
5 LION KING DOULE BED 2015-07-15 10000 20
I. SELECT COUNT(DISTINCT TYPE) FROM INTERIORS;
II. SELECT SUM(PRICE) FROM INTERIORS WHERE TYPE = ‘BABY COT’;
5 Aryan, a database administrator, has grouped records of a table with the 2
help of group by clause. He needs to further filter groups of records
generated through group by clause. Suggest suitable clause for it and
properly explain its usage with the help of an example.
100 | P a g e
She need to perform following task on the table so help her to write the SQL
query: -
i. To fetch last 1 character from the flight number column.
ii. To display the values of flight name column in upper case.
8 Given Table Course: 2
Find out the output for given SQL command:
11
Devansh, a database analyst has created the following table: Salesman
He has written following queries:
(a) select sum(salary) from salesman where bonus is null and Salary>
20000;
(b) select avg(salary)+min(bonus) from salesman where storetype=
‘Health’;
(c) select max(salary) from salesman where storetype= ‘software’;
(d) select length(SNAME) from salesman where bonus is NULL;
(e) select count(bonus) from salesman ;
TOTAL 25
101 | P a g e
KENDRIYA VIDYALAYA SANGATHAN, AHEMDABAD REGION
NAME OF CHAPTER/ TOPIC: DATABASE QUERY USING SQL
WORKSHEET NO.:3 (Answers) ::CLASS XII – IP
QN Answers M
1 b.AVG() 1
2 c. ORDER BY 1
3 b. HAVING 1
4 i. 3 2
ii. 17500
5 With group by clause for more filter Having clause is used. 2
Example:
SELECT DEPTNO, COUNT(*) FROM EMP
GROUP BY DEPTNO
HAVING COUNT(*)>3;
6 I. 4 2
II. BHARAT A
7 i. SELECT RIGHT(FNO,1) FROM PASSENGER; 2
ii. SELECT UPPER(FNAME) FROM PASSENGER;
8 i) TID COUNT(*) MIN(FEES) 2
101 2 12000
ii) FEES DAY(STARTDATE)
20000 1
18000 25
9 I. 11 3
II. cbse
III. exams
10 i. SELECT * FROM ITEM ORDER BY STOCKDATE DESC; 4
ii. SELECT TYPE, COUNT(*) FROM ITEM GROUP BY TYPE;
iii. SELECT MIN(PRICE) FROM ITEM;
iv. SELECT ITEMNAME, ROUND(PRICE,1) FROM ITEM;
11 i. 180000 5
ii. 35025.34
iii. 80000
iv. 5
5
5
v. 5
TOTAL 25
102 | P a g e
KENDRIYA VIDYALAYA SANGATHAN, AHEMDABAD REGION
NAME OF CHAPTER/ TOPIC: DATABASE QUERY USING SQL
WORKSHEET NO.:4 (Questions) ::CLASS XII – IP
QN Question M
1 The COUNT() function ignores duplicate and null values while counting 1
the records. State True or False.
a. True
b. False
2 In MYSQL, …….. option causes a group function to consider only 1
unique values of the argument expression.
a. DESC
b. ORDER BY
c. DISTINCT
d. None of the above
3 Which SQL statement do we used to find the total number of records 1
present in the table product?
a. SELECT * FROM PRODUCT;
b. SELECT COUNT(*) FROM PRODUCT;
c. SELECT FIND(*) FROM PRODUCT;
d. SELECT SUM() FROM PRODUCT;
4 Briefly explain the purpose of the following SQL functions: 2
i. power()
ii. mod()
103 | P a g e
10
104 | P a g e
KENDRIYA VIDYALAYA SANGATHAN, AHEMDABAD REGION
NAME OF CHAPTER/ TOPIC: DATABASE QUERY USING SQL
WORKSHEET NO.:4 (Answers):: – CLASS XII – IP
QN Answers M
1 a. False 1
2 b. DISTINCT 1
3 b. SELECT COUNT(*) FROM PRODUCT; 1
4 i. pow(m,n) returns the value m raise to power n 2
ii. mod(a,b) returns the remainder after a divide by b
5 SELECT Author, Max(Price) FROM LIBRARY GROUP BY AUTHOR; 2
Group By clause is used to group the rows together that contain
the same values in a specified column.so to display maximum
price of each author , the table must be grouped author wise
using group by clause.
6 i. Sang 2
ii. than
7 i. SELECT LEFT(NAME,4) FROM STUDENT; 2
ii. SELECT SUBSTR(CITY,4) FROM STUDENT;
8 ROUND () – Converts the value to rounded upto n decimal 2
SQRT() – Finds the square root of a given number n
9 i. Now() returns system date and time 3
ii. No parameter
iii. Yyyy-mm-dd hh:mm:ss
TOTAL 25
105 | P a g e
KENDRIYA VIDYALAYA SANGATHAN – AHMEDABAD REGION
CLASS XII – IP
NAME OF CHAPTER/ TOPIC: DATABASE QUERY USING SQL
WORKSHEET NO.:5 (Questions)
QN Question M
1 Write the output of the following command: 1
SELECT ROUND(49.88);
a. 49.88
b. 49.0
c. 9.8
d. 50
2 Write output of the following : 1
SELECT LEFT(‘INDIA IS GREAT’,5);
a. INDIA
b. GREAT
c. INDIA IS
d. IS GREAT
3 Assertion (A) : SELECT MOD(15,3); will produce the output as 0. 1
Reason (R) : POWER() function is used to get the power of the given
values.
a. Both Assertion(A) and Reason(R) are true and Reason(R) is the
correct explanation of assertion (A).
b. Both Assertion(A) and Reason(R) are true but Reason(R) is not the
correct explanation of assertion (A).
c. Assertion (A) is true but reason(R) is false.
d. Assertion (A) is false but reason(R) is true.
4 Find the output of the following query: 2
(i) SELECT ROUND(7658.345,2);
(ii) SELECT MOD(ROUND(13.9,0),3);
5 Find the output of the following SQL queries: 2
i) SELECT SUBSTR(‘FIT INDIA MOVEMENT’,5);
ii) SELECT INSTR(‘ARTIFICIAL INTELIGENCE’, ‘AI’);
6 A relation Vehicles is given below : 2
106 | P a g e
9 Consider a table "MYPET" with the following data: 3
TOTAL 25
107 | P a g e
KENDRIYA VIDYALAYA SANGATHAN – AHMEDABAD REGION
CLASS XII – IP
NAME OF CHAPTER/ TOPIC: DATABASE QUERY USING SQL
WORKSHEET NO.:5 (Answers)
Q.No. Answers Marks
1 d. 50 1
2 a. INDIA 1
3 c. Both Assertion(A) and Reason(R) are true but Reason(R) is not 1
the correct explanation of assertion (A).
4 i) 7658.34 2
ii) 2
5 i) ‘INDIA MOVEMENT’ 2
ii) 0
6 a. COMPANY COUNT(*) 2
Maruti 2
Mahindra 2
Mitsubishi 1
Datsun 1
(b)
(c)
d) 4
108 | P a g e
KENDRIYA VIDYALAYA SANGATHAN – AHMEDABAD REGION
CLASS XII – IP
NAME OF CHAPTER/ TOPIC: DATABASE QUERY USING SQL
WORKSHEET NO.:6 (Questions)
QN Question M
1 Write the output of the following SQL statement: 1
SELECT ROUND(458.45,-1);
a. 450
b. 460
c. 458
d. 500
2 The SUBSTR() function in MYSQL is an example of …………. 1
a. Date function
b. Text function
c. Aggregate function
d. Math function
3 Assertion (A) :SELECT INSTR(‘WORD MAP’, ‘MAP’); will produce the 1
output 6.
Reason (R) : INSTR() function takes two arguments as string and
substring and returns the position of the first occurrence of a
specified substring from a given string.
a. Both Assertion(A) and Reason(R) are true and Reason(R) is the
correct explanation of assertion (A).
b. Both Assertion(A) and Reason(R) are true but Reason(R) is not the
correct explanation of assertion (A).
c. Assertion (A) is true but reason(R) is false.
d. Assertion (A) is false but reason(R) is true.
4 Sreenath created the following table STUDENT in his database. 2
Table : STUDENT
Rollno Name CLASS Mark
1 Ritika 12 40
2 Angad 12 35
3 Kaveri 11 42
4 Lalitha 12 21
5 Daniel 11 44
6 Rabindra 11 39
7 Rabia 11 28
He wants to now count number of students in each CLASS where the
number of students is more than 3. He has executed the following
query.
SELECT MAX(MARKS) FROM STUDENT WHERE COUNT(*)>3 GROUP BY
CLASS;
But, he got an error. Identify the error and rewrite the query.
5 Briefly explain the purpose of the following SQL functions: 2
i. NOW() ii. RTRIM( )
6 Help suman in predicting the output of the following queries: 2
i) select length(mid(‘NETWORKING’,2,3));
ii) select DAYOFYEAR(‘2012-02-08’);
7 A numeric data field AMOUNT store a value 936.432, Write MySQL 2
query for the following
i) to display amount up to one(1) decimal.
ii) to display amount as a whole number.
109 | P a g e
8 Consider the following SQL string : ‘Examination’ 2
Write commands to display:
a) ‘min’
b) ‘nation’
OR
Write SQL
Commands for the following:
I. Display the maximum and minimum price of drugs offered by all
pharmacies.
II. Display sum of price for each PharmacyName having more than
one drug.
III. To display total no of drug of each pharmacy name.
IV. Display details of PHARMADB in descending order of price.
11 Write the SQL functions which will perform the following operations: 5
i) To display the name of the day of the current date.
ii) To remove spaces from the beginning of a string, “ Python”.
iii) To display the name of the month eg, January or February from
your date of birth.
iv) To display the starting position of word “Information” from
“Information Technology”
v) To compute the power of two numbers a and b
TOTAL 25
110 | P a g e
KENDRIYA VIDYALAYA SANGATHAN – AHMEDABAD REGION
CLASS XII – IP
NAME OF CHAPTER/ TOPIC: DATABASE QUERY USING SQL
WORKSHEET NO.:6 (Answers)
QN Answers Marks
1 d.460 1
2 b. Text function 1
3 a. Both Assertion(A) and Reason(R) are true and Reason(R) is the correct 1
explanation of assertion (A).
4 To filter more condition with group by clause HAVING clause is used in 2
place of WHERE clause. Correct query is
SELECT MAX(MARKS) FROM STUDENT
GROUP BY CLASS
HAVING COUNT(*)>3;
5 i) Now() – it generates system date and time at the time of 2
execution of command
ii) RTRIM()- function removes the trailing spaces.
6 i) 3 II) 39 2
7 i) Select Round(Amount,1); 2
ii) Select Round(Amount,0);
8 a) select substr("Examination",4,3); 2
OR
select substring("Examination",4,3);
OR
select mid("Examination",4,3);
b) select substr("Examination",6,6);
OR
select substring("Examination",6,6);
OR
select mid("Examination",6,6);
OR
a) select instr("Examination","min");
OR
select position("min" in "Examination");
b) select right("Examination",5);
9 i. Select dayname(‘2020-02-30’); 3
ii. Select lower(emailed);
iii. Select length(name);
10 i) Select PharmacyName,max(Price),min(Price) from PHARMADB; 4
ii) Select PharmacyName, sum(Price) from PHARMADB group by
PharmacyName having count(*)>1;
iii) Select SUM(PRICE) from PHARMADB group by PharmacyName;
iv) Select * from PHARMADB order by price desc;
11 i) dayname(date(curdate())) 5
ii) ltrim(“ Python“)
iii) monthname(date(dob))
iv) instr(“Information Technology”,”information”)
v) pow(a,b)
TOTAL 25
111 | P a g e
KENDRIYA VIDYALAYA SANGATHAN – AHMEDABAD REGION
CLASS XII – IP
NAME OF CHAPTER/ TOPIC: DATABASE QUERY USING SQL
WORKSHEET NO.:7 (Questions)
QN Question M
1 Write the output of the following SQL command: 1
SELECT SUBSTR(‘COMPUTER’,3,4);
a. MPUT
b. PU
c. PUTE
d. MP
2 The string function that returns the index of first occurrence of substring 1
is ………….
a. INSERT()
b. INSTR()
c. INSTRING()
d. INFSTR()
3 Assertion (A) : HAVING clause is often used with the GROUP BY 1
clause.
Reason (R) : HAVING clause is used to check specified condition.
a. Both Assertion(A) and Reason(R) are true and Reason(R) is the
correct explanation of assertion (A).
b. Both Assertion(A) and Reason(R) are true but Reason(R) is not the
correct explanation of assertion (A).
c. Assertion (A) is true but reason(R) is false.
d. Assertion (A) is false but reason(R) is true.
4 Give any two differences between POW () and SUM (). 2
5 Ms. Mohini is working in a school and stores the details of all students in 2
a table school data.
Table : SCHOOLDATA
Write the SQL statements from the above given table to:
i) To remove leading spaces from the column name
ii) Display the names of the students who were born on Sunday
6 Predict the output of the following queries: 2
i. Select round(6.5675,2);
ii. Select mid(‘PRE_BOARD_EXAM’,4,6);
7 Write the output of the following SQL queries: 2
i. SELECT DAYOFMONTH(‘2015-01-16’);
ii. SELECT DAYOFYEAR(‘2014-01-30’);
8 Consider the table HOTEL given below: 2
Empno Category Salary
E101 Manager 60000
112 | P a g e
E102 Executive 65000
E103 Clerk 40000
E104 Manager 62000
E105 Executive 50000
Mr. Vinay wanted to display average salary of each category. He
entered the following SQL statement. Identify the error and rewrite the
correct SQL statement.
SELECT CATEGORY, SALARY FROM HOTEL
GROUP BY CATEGORY;
9 Predict the output of the following queries: 3
i. SELECT INSTR (‘Very good’, 'good');
ii. SELECT MID('Quadratically',5,6);
iii. SELECT RIGHT (‘Command', 3);
10 Carefully observe the following table named ‘stock’. 4
PID PName Category Qty Price
1 Keyboard IO 15 450
2 Mouse IO 10 350
3 Wifi-router NW 5 2600
4 Switch NW 3 3000
5 Monitor O 10 4500
6 Printer O 4 17000
i. To display the records in decreasing order of price.
ii. To display category and category wise total quantities of
products.
iii. To display the category and its average price.
iv. To display category and category wise highest price of the
products.
11 Write the SQL functions which will perform the following operations: 5
i) To display the day of the current date.
ii) To display the first four letter of the text “EDUCATION”.
iii) To display the text “EDUCTAION” in lower case.
iv) To remove spaces from the beginning and end of a string, “ CBSE ”.
v) To compute the sum between two numbers, n1 and n2
TOTAL 25
113 | P a g e
KENDRIYA VIDYALAYA SANGATHAN – AHMEDABAD REGION
CLASS XII – IP
NAME OF CHAPTER/ TOPIC: DATABASE QUERY USING SQL
WORKSHEET NO.:7 (Answers)
QN Answers M
1 a. MPUT 1
2 b. INSTR () 1
3 a. Both Assertion(A) and Reason(R) are true and Reason(R) is the 1
correct explanation of assertion (A).
4 POW() – return the value m raise to power n, Type of mathematical 2
function
SUM() – return the sum of all the values of a given column, aggregate
function
5 i) SELECT LTRIM(NAME) FROM SCHOOLDATA; 2
ii) SELECT NAME FROM SCHOOLDATA WHERE DAYNAME(DOB) =
‘SUNDAY’;
6 i. 6.57 2
ii. _BOARD
7 i. 16 2
ii. 30
8 Correct statement : 2
SELECT CATEGORY, AVG(SALARY) FROM HOTEL
GROUP BY CATEGORY;
9 i. 6 3
ii. ratica
iii. and
10 i. SELECT * FROM STOCK ORDER BY PRICE DESC; 4
ii. SELECT CATEGORY, SUM(QTY) FROM STOCK GROUP BY
CATEGORY;
iii. SELECT CATEGORY, AVG(PRICE) FROM STOCK GROUP BY
CATEGORY;
iv. SELECT CATEGORY, MAX(PRICE) FROM STOCK GROUP BY
CATEGORY;
11 I. SELECT year(NOW()); 5
II. SELECT LEFT(‘EDUCATION’,4);
III. SELECT LOWER(‘EDUCATION’);
IV. SELECT LTRIM(“ CBSE ”);
V. SELECT SUM(N1,N2);
TOTAL 25
114 | P a g e
KENDRIYA VIDYALAYA SANGATHAN – AHMEDABAD REGION
CLASS XII – IP
NAME OF CHAPTER/ TOPIC: DATABASE QUERY USING SQL
WORKSHEET NO.:8 (Questions)
Q Question M
N
1 Which of the following is not a built-in function? 1
a. SUM
b. AVG
c. MAX
d. TOTAL
2 What is returned by INSTR(‘JAVA POINT’,’P’); ? 1
a. 6
b. 7
c. Point
d. JAVA
3 Assertion (A): SELECT RIGHT(‘Program’,4) ; Output will be ‘ram’ 1
Reason (R) : It is used to return a specified number of characters
from the right of the string. The number of characters returned is
determined by the second argument.
a. Both Assertion(A) and Reason(R) are true and Reason(R) is the
correct explanation of assertion (A).
b. Both Assertion(A) and Reason(R) are true but Reason(R) is not the
correct explanation of assertion (A).
c. Assertion (A) is true but reason(R) is false.
d. Assertion (A) is false but reason(R) is true.
4 Predict the output of the following queries based on the given table: 2
115 | P a g e
7 What will be the output of : 2
i. SELECT ROUND(124.44) + MOD(1201,3);
ii. SELECT MOD(30.500,5) + ROUND(100.50,1);
8 Differentiate between SUBSTR() and INSTR(). 2
9 A school “ABC” maintains the following MySQL table named ‘student’ 3
having following structure to store the details of their students:
116 | P a g e
KENDRIYA VIDYALAYA SANGATHAN – AHMEDABAD REGION
CLASS XII – IP
NAME OF CHAPTER/ TOPIC: DATABASE QUERY USING SQL
WORKSHEET NO.:8 (Answers)
QN. Answers M
1 d. TOTAL 1
2 a.6 1
3 a.Assertion (A) is false but reason(R) is true. 1
4 i) 91 2
ii) F Swapnil Pant
M Rahil Arora
5 i) BES 2
ii) WELCOME SINGH
6 i) SELECT TID, MIN(FEES) FROM COURSE 2
GROUP BY TID;
ii) SELECT * FROM COURSE WHERE MONTH(STARTDATE)=7;
7 i. 125 2
ii. 101.000
8 SUBSTR(): 2
It is used to extract a set of character from a string by specifying the
character starting position and end position and length of characters
to be fetched.
Eg:
SELECT SUBSTR(‘Hello’,2,3);
Output : ‘ell’
INSTR():
It is used to find the position of any particular character in a word
which returns numeric value.
Eg:
SELECT INSTR(‘Hello’,’e’);
Output : 2
9 i. SELECT UPPER(LEFT(STREAM,3)) FROM STUDENT; 3
ii. SELECT YEAR(DOB) FROM STUDENT;
iii. SELECT INSTR(STREAM , ‘SCI’) FROM STUDENT;
10 i. Select max(marks) from student group by gender; 4
ii. Select min(marks) from student group by city;
iii. Select gender, count(gender) from student group by gender;
iv. Select CLASS, sum(marks) from student group by CLASS;
11 I. 63 5
II. 800
III. 450
IV. 4
V. 6
5
TOTAL 25
117 | P a g e
KENDRIYA VIDYALAYA SANGATHAN – AHMEDABAD REGION
CLASS XII – IP
NAME OF CHAPTER/ TOPIC: DATABASE QUERY USING SQL
WORKSHEET NO.:9 (Questions)
QN Question M
1 Which of the following is correct answer of given query? 1
SELECT MOD(26,5);
a. 2 b. 3 c.4 d.1
2 Assertion (A) : The ORDER BY clause sorts the result set in 1
descending order by default.
Reason (R) : To sort a result set in ascending order we can use ASC
keyword with ORDER BY clause.
a. Both Assertion(A) and Reason(R) are true and Reason(R) is the
correct explanation of assertion (A).
b. Both Assertion(A) and Reason(R) are true but Reason(R) is not
the correct explanation of assertion (A).
c. Assertion (A) is true but reason(R) is false.
d. Assertion (A) is false ut reason(R) is true.
3 Which keyword is used to arrange the result of order by clause in 1
descending order?
a. DSEC b.DES c.DESC d.DESNO
4 Briefly explain the purpose of the following SQL functions: 2
i. SUBSTR() ii. LEFT()
5 Help Reshma in predicting the output of the following queries: 2
i) select round(783.34,-2);
ii) select round(456.335,2);
6 Given Table Course: 2
118 | P a g e
He has written following queries :
i) Select MAX(DOB ) from emp;
ii) Select ENAME from EMP where YEAR(DOJ)=2020;
9 Consider the table Garment and write the query: 3
119 | P a g e
KENDRIYA VIDYALAYA SANGATHAN – AHMEDABAD REGION
CLASS XII – IP
NAME OF CHAPTER/ TOPIC: DATABASE QUERY USING SQL
WORKSHEET NO.:9 (Answers)
Q.No. Answers Marks
1 d. 1 1
2 d. Assertion (A) is false but reason(R) is true 1
3 c. DESC 1
4 i. SUBSTR (str, m, n) – extracts the substring from m position 2
onwards and n number of characters.
ii. LEFT () – extracts n characters from the left side of the
given string
5 i) 800 2
ii) 456.34
6 i) 101, 2, 12000 2
ii) 12000 02
15000 15
10000 01
9000 15
20000 01
18000 25
7 I. AVG(POINTS) 2
45
II. COUNT(POINTS)
2
8 i. 2001 2
ii. ANUJ
9 i. SELECT MIN(PRICE) FROM GARMENT; 3
ii. SELECT SIZE, COUNT (*) FROM GARMENT GROUP BY SIZE
HAVING COUNT (*)>1;
iii. SELECT SUM(PRICE) FROM GARMENT GROUP BY COLOUR;
10 i. 91 4
ii. 194
iii. 94.6
iv. 5
11 i. SELECT LENGTH(FacultyName) from faculty; 5
ii. SELECT ROUND (234.6789,3);
iii. SELECT RIGHT (LASTNAME,5) from faculty;
iv. SELECT DAYOFYEAR (DOB) from faculty;
v. SELECT SUBSTR(ADDRESS,3,2) from faculty;
TOTAL 25
120 | P a g e
KENDRIYA VIDYALAYA SANGATHAN – AHMEDABAD REGION
CLASS XII – IP
NAME OF CHAPTER/ TOPIC: DATABASE QUERY USING SQL
WORKSHEET NO.:10 (Questions)
QN Question M
1 Find the Output of SQL command : 1
select concat (concat (‘Inform’, ‘atics’),‘Practices’);
a. Informatics Practices
b. Informatic Practices
c. Inform practices
d. Inform atics practices
2 The outputs of the given two commands are 20 and 17 respectively. 1
Select COUNT(*) From Student;
Select COUNT(Age) From Student;
How many NULL values are there in Age column of the Student table?
a. 17
b. 20
c. 3
d. None of these
3 If column “Fees” contains the data set (5000,8000,7500,5000,8000), 1
what will be the output after the execution of the given query?
SELECT SUM (DISTINCT Fees) FROM student;
i. 20500
ii. 10000
iii. 20000
iv. 33500
4 State any two differences between single row functions and multiple row 2
functions.
5 Consider the decimal number x with value 8459.2654. Write commands 2
in SQL to:
i. round it off to a whole number
ii. round it to 2 places before the decimal.
6 Anjali writes the following commands with respect to a table employee 2
having fields, empno, name, department, commission.
Command1 : Select count(*) from employee;
Command2: Select count(commission) from employee;
She gets the output as 4 for the first command but gets an output 3 for
the second command. Explain the output with justification.
7 Consider the following SQL string: “Preoccupied” Write commands to 2
display:
a. “occupied”
b. “cup”
8 Considering the same string “Preoccupied” Write SQL commands to 2
display:
a. the position of the substring ‘cup’ in the string “Preoccupied”
b. the first 4 letters of the string
9
121 | P a g e
Write SQL commands to:
a. Display the average price of each type of vehicle having quantity
more than 20.
b. Count the type of vehicles manufactured by each company.
c. Display the total price of all the types of vehicles.
10
122 | P a g e
KENDRIYA VIDYALAYA SANGATHAN – AHMEDABAD REGION
CLASS XII – IP
NAME OF CHAPTER/ TOPIC: DATABASE QUERY USING SQL
WORKSHEET NO.:10 (Answers)
QN Answers M
1 a. Informatics Practices 1
2 c. 3 1
3 I.20500 1
4 Differences between single row functions and multiple row functions. 2
i)Single row functions work on one row only whereas multiple row
functions group rows
ii)Single row functions return one output per row whereas multiple row
functions return only one output for a specified group of rows
5 i. select round(8459.2654); 2
ii. select round(8459.2654,-2);
6 This is because the column commission contains a NULL value and the 2
aggregate functions do not take into account NULL values. Thus
Command1 returns the total number of records in the table whereas
Command2 returns the total number of non NULL values in the column
commission.
7 a. select substr("Preoccupied", 4); 2
or select substring("Preoccupied", 4);
or select mid("Preoccupied",4);
or select right(("Preoccupied"”, 8);
123 | P a g e
KENDRIYA VIDYALAYA SANGATHAN, AHEMDABAD REGION
NAME OF CHAPTER/ TOPIC: DATABASE QUERY USING SQL
Q.No. Question Ma
rks
1 Which of the following is the correct output of the following SQL 1
command?
SELECT ROUND(7876.4568,2);
(i) 7876.46 (iii) 7876.45
(ii) 7900 (iv) 7900.4568
2 Aggregate functions are also known as : 1
(i) Scalar functions (iii)Single Row Functions
(ii) Multiple Row functions (iv)Hybrid Functions
3 Primary law in India for matters related to e-commerce and cyber 1
crime is :
(i) IT Act 1995 (iii) IT Act 2000
(ii) IT Act 1998 (iv) IT Act 2010
4 Ravisha as stored the records of all students of her class in a MYSQL 1
table. Suggest a suitable SQL clause that she should use to display the
names of students in alphabetical order.
(i) SORT BY (iii) ALIGN BY
(ii) GROUP BY (iv) ORDER BY
5 To remove the leading and trailing space from data values in a column 1
of MySql table, we use
(i) Left() (iii) Right()
(ii) Trim() (iv) Ltrim
6 If the substring is not present in a string, the INSERT() returns: 1
(i) -1 (iii) 1
(ii) NULL (iv) 0
7 Differentiate between COUNT() and COUNT(*) functions in MYSQL. 2
Give suitable examples to support your answer.
8 Keshav has written the following query to find out the sum of bonus 2
earned by the employees of WEST zone.
SELECT zone, TOTAL(bonus) FROM employee HAVING zone = ‘WEST’;
But he got an error. Identify the errors and rewrite the query by
underlining the correction(s) done.
9 Consider the table Patient given below and write SQL Commands. 3
Table : Patiend
Patientid Name City Phone Dateofadm Departmen
t
1000001 Ritvik Garg Delhi 68476213 2021-12-10 Surgery
1000002 Rahil Arora Mumbai 36546321 2022-01-08 Medicine
1000003 Mehak Bhatt Delhi 68421879 2022-02-02 Cardiology
1000004 Soumik Rao Delhi 26543266 2022-01-11 Medicine
1000005 Suresh Sood Bangalore 65432442 2021-03-09 Surgery
(i) Display the details of all patients who were admitted in
January.
(ii) Count the total number of patients from Delhi.
(iii) Display the last 2 digits of the Patientid of all patients from
Surgery Department.
124 | P a g e
10 Write an output (i-iii) for the following SQL commands. 3
Table : FASHION
ID Product Price Qty
F01 Kajal 970 10
F02 Foundation 2100 15
F03 Night Cream 1700 20
F04 Day Cream 1400 10
F05 Shampoo 1200 25
F06 Lipstick 850 32
125 | P a g e
KENDRIYA VIDYALAYA SANGATHAN, AHEMDABAD REGION
NAME OF CHAPTER/ TOPIC: DATABASE QUERY USING SQL
126 | P a g e
1 Compact Petrol 56000 70000
HatchBack
2 Compact Diesel 34000 40000
HatchBack
3 MUV Petrol 33000 35000
4 MUV Diesel 14000 15000
5 SUV Petrol 27000 54000
6 SUV Diesel 18000 30000
7 Sedan Petrol 8000 10000
8 Sedan Diesel 1000 5000
i. Display fuel wise average sales in the first quarter
ii. Display segment wise highest sales in the second quarter
iii. Display the records in the descending order of sales in the
second quarter.
10 Write MySQL statements for the following : 3
i. To create a database named FOOD.
ii. To create a table named Nutrients based on the following
specification:
Column Name DataType Constraints
Food_Item Varchar(20) Primary key
Calorie Integer
11 Preeti manages database in a blockchain start-up. For business 4
purposes, she created a table named BLOCKCHAIN. Assist her by
writing the following queries:
Table : BLOCKCHAIN
Id User Value Hash Transaction_date
1 Steve 900 ERTYU 2020-09-19
2 Meesha 145 @345r 2021-03-23
3 Nimisha 567 #wert5 2020-05-06
4 Pihu 678 %rtyu 2022-07-13
5 Kopal 768 rrt4% 2021-05-15
7 Palakshi 534 wer@3 2022-11-29
127 | P a g e
KENDRIYA VIDYALAYA SANGATHAN, AHEMDABAD REGION
NAME OF CHAPTER/ TOPIC: DATABASE QUERY USING SQL
WORKSHEET NO.:13 (Questions from Revision of Class XI) ::CLASS XII – IP
128 | P a g e
10 Write an SQL query to join two tables on the basis of common field Code and display the 3
subject in ascending order. Detail of the table are given below:
Table :BOOK
Code Subject
B1 ENGLISH
B2 PHYSICS
B3 HISTORY
B4 SCIENCE
Table : STOCK
S_CODE PUB QTY CODE
P12 GYAN CHAND 250 B1
P14 PUSTAK HOUSE 340 B2
P16 SONKA BOOKS 245 B3
11 The table Professional is created in a database. The details of the 4
different professional courses are given below:
Ref_ID Course Duration Eligibility Fee
M/001 MBA 2 Graduate 600000
B/--2 B.Tech 4 UG 750000
Graduate
B/003 B.Pharm 4 UG 780000
Graduate
B/004 BBA 3 UG 530000
Graduate
M/002 MSc 2 Graduate 480000
M/003 MCA 2 Graduate 500000
i) To display ref_id, courses and fee whose duration is 3 years or
more.
j) To display all such courses with the fee whose eleigibility is
‘Graduate’
k) To reduce the fee for all the courses by 50000
l) To display the courses, their duration and eligibility whose fee
is in the range to 500000 to 750000.
12 Monika has created following table named WORKER: 5
W_ID F_NAME L_NAME CITY STATE
102 SAHIL KHAN KANPUR UTTAR
PRADESH
104 SAMEER PARIKH ROOP PUNJAB
NAGAR
105 MARY JONES DELHI DELHI
106 MAHIR SHARMA SONIPAT HARYANA
107 ATHARVA BHARDWAJ DELHI DELHI
108 VEDA SHARMA KANPUR UTTAR
PRADESH
(i) Insert a new record in the table having following values:
[109,’SONA’, ‘GEORGE’, ‘SURAT’,’GUJARAT’]
(ii) To change the value of state from ‘PUNJAB’ to ‘HARYANA’.
(iii) To remove the records of those students whose L_Name is
‘SHARMA’.
(iv) To add a new column ‘WAGE’ of suitable datatype.
(v) To display records of city as ‘DELHI’.
25
129 | P a g e
KENDRIYA VIDYALAYA SANGATHAN (AHMEDABAD REGION)
2023-24
CLASS XII – IP
NAME OF THE CHAPTER: Introduction to Computer Network
WORKSHEET : 1
130 | P a g e
NAME OF THE CHAPTER: Introduction to Computer Network
WORKSHEET : 1 (Answers)
9 a) Bus topology 2
b) Star topology
10 Gmail, Yahoo Mail 2
11 A switch is more intelligent than a hub. As a hub, a switch is the connection point 2
for the computers (and other devices) in a network. However, a switch is more
efficient at passing along traffic. It records the addresses of the computers
connected to it in a table.
12 Static web page: 2
Content on the server is served upto any visitor the same(every time)
Contains simple HTML code
No additional software is required
Dynamic web page:
Content on the server is the same, but displays different data depending on
information searched
Contains dynamic code along with simple HTML code
Additional software must be installed on the server to create the web page.
13 Cookies are small text files stored on a user's computer and created and used by 2
websites to remember basic information or to record the user's browsing activity.
14 A web browser is a program that renders a webpage from a website through a 2
URL. Web browsers are also responsible for collecting data from the web server
as well as capable to retrieve hyper documents, links and media.
For example, Google Chrome, Internet Explorer, Mozilla Firefox.
15 IMAP, POP3, SMTP 3
131 | P a g e
KENDRIYA VIDYALAYA SANGATHAN (AHMEDABAD REGION)
2023-24
CLASS XII – IP
NAME OF THE CHAPTER: Introduction to Computer Network
WORKSHEET : 2
(i) Suggest an ideal cable layout for connecting the above UNITs.
(ii) Suggest the most suitable place i.e. UNIT to install the server for the above
NGO.
(iii) Which network device is used to connect the computers in all UNITs?
(iv) Suggest the placement of Repeater in the UNITs of above network.
(v) NGO is planning to connect its head office in Delhi, which is more than 1500
km from NGO. Which type of network out of LAN, WAN or MAN will be formed?
2 Vidyadevi was inspired by her granddaughter who uses technology for hr day 5
to day activities. Being a learner and teacher all her life, he wanted to open an
email account and interact with her friends and family. Her granddaughter
created an email account for her and he started sending mails to her friends.
This was a big achievement for her. Her granddaughter explained her how to
132 | P a g e
send mails, how to create email address, what protocols are used. There are
few doubts in her mind which you can help her with.
iii) Mail access tarts with client when user needs to download email from the
______.
(a)mailbox (b)mail server (c)IP server (d)Internet
Number of computers :
133 | P a g e
ii) Suggest the most suitable place to house the server. Justify your answer
iii) Suggest the placement of following devices with justification:
a)repeater b) hub/switch
AGRA
DELHI
PRODUCTION Office WAREHOUSE
head
Office
ADMIN SHIPPING
Number of computers:
ADMIN 120
WAREHOUSE 60
PRODUCTION 35
SHIPPING 18
Delhi Head Office 12
i) Suggest the most appropriate location of the server inside the AGRA Office
(out of the four buildings) to get the best connectivity for maximum
number of computers. Justify your answer.
ii) Suggest and draw cable layout to efficiently connect various buildings
134 | P a g e
within the AGRA Office for a wired connectivity.
iii) Which networking device will you suggest to be procured by the company
to interconnect all the computers of various buildings of AGRA Office?
iv) Company is planning to get its website designed which will allow
shopkeepers to see their products, shipping details themselves on its
server. Out of the static or dynamic, which type of website will you
suggest?
v) Which of the following will you suggest to establish the online face to
face communication between the people in the ADMIN office of AGRA
and Delhi head office?
5 Samarth is the hardware engineer of IT company. He has been given the task 5
of installing a network in the school lab which has around 40 computers.
i)Suggest the most suitable type of network topology he should use in order to
maximize speed and make each computer independent of network breakdowns.
a)bus topology b)star topology c)ring topology d)mesh topology
ii)In order to allow data transfer from server to only the intended computers
which network device is required in the lab to connect the computers?
a) switch b)hub c)router d)gateway
iii) After setting up the lab and internet in the lab, Samarth is now required to
enable videos and animations to be played on the web browser for students of
multimedia class. Which browser tool/service can be used ?
135 | P a g e
NAME OF THE CHAPTER: Introduction to Computer Network
WORKSHEET : 2 (Answers)
i)
136 | P a g e
KENDRIYA VIDYALAYA SANGATHAN (AHMEDABAD REGION)
2023-24
CLASS XII – IP
NAME OF THE CHAPTER: Societal Impacts
WORKSHEET : 1
1. Phishing 2. Hacking
137 | P a g e
NAME OF THE CHAPTER: Societal Impacts
WORKSHEET : 1 (Answers)
9 The Indian IT Act refers to providing guidelines and rules to the user on the 2
processing, storage and transmission of sensitive information.
The states of our country have their own cyber cells in the police station to
report cybercrime.
The IT act provides legal provisions and implications against cybercrime.
If the cybercrime is proved then the accused may get the penalties also.
13 When we are using the internet we are leaving some data like filling up 3
forms, replies to emails, social media status updates etc known as digital
footprints.
The data and personal records leftover on the internet while using the
internet are called digital footprints.
138 | P a g e
Passive Digital Footprints: Passive digital footprints are created without the
user’s consent. It is created by a server, or app or the platform used by the
user.
14 IPR : rights of the owner of the information to decide how much information 3
is to be exchanged, shred or distributed.
common type of IPR which are protected by the law :
139 | P a g e
KENDRIYA VIDYALAYA SANGATHAN (AHMEDABAD REGION)
2023-24
CLASS XII – IP
NAME OF THE CHAPTER: Societal Impacts
WORKSHEET : 2
Reasoning (R):- Mostly all electronic waste comprises of toxic chemicals such
as lead, beryllium, mercury etc.
5 Define e-waste. What are the various methods for effective e- waste 2
management?
6 What do you mean by Digital property rights? Explain. 2
7 Give any 2 benefits of ICT on today’s society? 2
8 State 2 benefits of e-waste recycling? 2
9 What do you understand by Net Etiquettes? Explain any two such etiquettes. 2
10 What are some side effects of spending too much time on computers? 3
11 What are the impacts of E-waste on the environment? 3
140 | P a g e
NAME OF THE CHAPTER: Societal Impacts
WORKSHEET : 2 (Answers)
9 There are some rules that you must obey when you are online and using the 2
Web/internet. These rules are called net etiquette (Netiquettes), Internet
etiquettes or Online etiquettes.
1. Be respectful.
2. Be aware of what you are commenting on social media.
3. Be careful with humor and sarcasm
4. Take care of how you are sharing your data and who can see this.
5. Friend requests and group invites should be checked before accepting
6. Take time to have a read of the rules of conduct/ community standards
7. Be forgiving do not take fight online
10 The Internet can be addictive 3
Can have a negative impact on our physical and psychological well being
Muscle and joint problems
Overuse injuries like swelling, pain, joint stiffness, weakness and numbness
Eyestrain
11 It pollutes air through the emission of gases and flumes in the atmosphere 3
It pollutes soil when dumped into the landfills by seeping harmful chemicals
into the soil
It pollutes the water by releasing the particles into the water of sea, rivers,
ponds or lakes
141 | P a g e
Case Based Questions:
QUES: XYZ Company developed software, related to face recognition with a team of 15
software developers. XYZ company Registered the software with a face symbol to easily
recognize their software. Before approval of software by the registering firm, Rohit one of the
team member of the software published the same software in internet under different name as
it is his own development.XYZ firm recognized this activity and informed to the police. The
police people arrested the Rohitas and removed the software from the internet. Police advice
the XYZ firm to apply for patent as the software is a new invention.
1. XYZ firm registered the software with face symbol to easily recognize their software .in this
context face symbol is called
(1) Copyright (2) IPR (3) Trademark (4) None of the above
Answer is: (3)
Answer is: 4
QUES: Mr. Vinod is the administrator of a school computer network. Help him to take
appropriate decision to achieve computer security and safe online access.
(i) Suggest a device to be used to filter network traffic to/from school network to provide
network security.
(ii) Which software he can use to get protection from Viruses and Spyware
(iii) Tell him what he has to disable if possible in browser so that online patterns are not tracked
(iv) Suggest an active protection mechanism so that he can find a solution to spam
(v) Suggest one active protection solution to PC Intrusion
Ans)
(i) Firewall
(ii) Anti-Virus and Anti-Spyware software
(iii) Cookies
(iv) Anti-Spam software
(v) Authorization/Authentication/Firewall
QUES: Mr. Seth who is a business man by profession faced following situations. Identify the
type of crime for each situation/incident happened to him?
(i) He was constantly receiving abusive emails
142 | P a g e
(ii) He clicked on an unknown link received as a result his personal sensitive information was
acquired by someone
(iii) Derogatory messages were posted on him online
(iv) His identity was used by someone to steal money
(v) His laptop was controlled by somebody in an unauthorized way
Ans)
(i) Cyber Bullying
(ii) Phishing
(iii) Cyber Trolls
(iv) Identity Theft
(v) Hacking
143 | P a g e