Professional Documents
Culture Documents
Practise Paper II
Practise Paper II
PRACTISE PAPER - II
Class-XII
Subject: Informatics Practices (065)
Module: Pandas
1. Consider the following DataFrame df and answer the questions from (A) to (E):
(A) Which command will be used to rename the index label (row label) 0 to 'Zero'.
i. df.rename({0 : 'Zero'}, axis = 0, inplace = 'True')
ii. df.rename({0 : Zero}, axis = 1, inplace = True)
iii. df.rename({'0' : 'Zero'}, axis = 1, inplace = True)
iv. df.rename({0 : 'Zero'}, axis = 0, inplace = True)
(B) Which of the following command will update the number of fours hit by 'Mr Virat' from 0 to 1?
i. df.iat [0, 3] = 1
ii. df.iat [0, 'Fours' ] = 1
iii. df.at [0, Fours ] = 1
iv. df.loc [0, 3] = 1
(C) Which of the following command will display the index labels of theDataFrame?
i. print(df.row)
ii. print(df.rows)
iii. print(df.indexes)
iv. print(df.index)
(D) Which of the following is correct code to add a column 'Boundaries' with sum of 'Fours' and 'Sixes'?
i. df. Boundaries = df ['Fours' ] + df ['Sixes' ]
ii. df ['Boundaries'] = df ['Fours' , 'Sixes' ]
iii. df. Boundaries = df ['Fours' , 'Sixes' ]
iv. df['Boundaries'] = df ['Fours' ] + df ['Sixes' ]
(E) Which of the following is correct code to delete the column 'Boundaries'.
i. df = df.delete(columns = ['Boundaries'])
ii. df = df.delete( )
iii. df = df.drop(columns = ['Boundaries'])
iv. df = df.drop(6)
2. Assertion (A): A Data frame is a two-dimensional labelled data structure like a table of MySQL.
Reason (R): It contains rows and columns, and therefore has both a row and column index.
Choose the correct option:
i. Both Assertion (A) and Reason (R) are true and Reason (R) is the correct explanation of Assertion
(A).
ii. Both Assertion (A) and Reason (R) are true but Reason (R) is not the correct explanation of
Assertion (A).
iii. Assertion (A) is true, but Reason (R) is false.
iv. Assertion (A) is false, but Reason (R) is true.
3. Given a Pandas series called Sequences, the command which will display the first 3 rows is ________.
i. print(Sequences.head(3))
ii. print(Sequences.Head(3))
iii. print(Sequences.heads(3)
iv. print(Sequences.Heads(3))
4. In a data frame, axis = 1 represents the _______ elements and axis = 0 _______.
i. rows, columns
ii. index, header
iii. columns, rows
iv. header, index
5. Ms. Sunania, a class teacher wants to add a new column, Grade with the values, A, B, A, A, B, A to a
data frame df. Help her choose the command to do so:
i. df.Grade = ['A', 'B', 'A', 'A', 'B', 'A']
ii. df.loc['Grade']= ['A', 'B', 'A', 'A', 'B', 'A']
iii. df ['Grade' ]=['A', 'B', 'A', 'A', 'B', 'A']
iv. Both ii) and iii) are correct
i. print(df['SNAME'])
ii. print(df.SNAME)
iii. Both i) and ii) are correct
iv. None of the above
7. Which of the following command will display the column labels of the data frame?
i. print(df.columns())
ii. print(df.column())
iii. print(df.column)
iv. print(df.columns)
8. Rahul, Sales Manager of Assam InfoTech Company uses following data frame Sales to store the sales
made by five sales persons in INR from year 2014 to 2017. Use the years as column labels, and sales
person names as row labels answer the questions from (A) to (E):
(A) Which method of pandas library is used to create the Sales data frame?
i. Dataframe()
ii. DataFrame()
iii. DATAFRAME()
iv. Framedata()
(B) Help Rahul to choose the correct output of the following Python code?
print(Sales.iat[1,3])
i. 50000
ii. 70000
iii. 60000
iv. 20000
(C) Rahul wants to view the datatypes of each column of Sales data frame.Help him to choose the
correct command out of the following?
i. print(Sales.dtypes)
ii. print(Sales.dtypes())
iii. print(Sales.Dtypes)
iv. print(Sales.Dtypes())
(D) Which of the following command is used to display the last two rows of Sales?
i. print(Sales.last(2))
ii. print(Sales.Tail(2))
iii. print(Sales.tail(2))
iv. print(Sales.Last(2))
(E) Which of the following command is used display the first two columns of Sales?
i. print(Sales.loc[ : , '2014':'2016' ])
ii. print(Sales.loc[ : , '2014':'2015' ])
iii. print(Sales.iloc[ : , : ])
iv. print(Sales.iloc[ : , 0: 1 ])
9. Sumita, a student of class-XII, has been assigned a code to create a pandas Series S1, as shown below.
With reference to the above Series S1 answer the questions for (A) to (E).
(A) Help her to identify the correct statement that can be used to extract the value with the index 'Apr'.
i. print(S1[Apr])
ii. print(S1['Apr'])
iii. print('S1'['Apr'])
iv. print(S1['3'])
(B) Which of the following command will display the following output
i. S1.values
ii. S1.keys()
iii. S1.values()
iv. S1.keys
(C) Choose the command that will give the following output
i. print(S1[:2])
ii. print(S1[0:3])
iii. print(S1[1:3])
iv. print(S1[2:4])
(D) Choose the command that will give the following output
i. print(S1.iloc[1:4])
ii. print(S1.iloc[2:4])
iii. print(S1.iloc(1:4))
iv. print(S1.iloc[1:4:2])
(E) Sumita wants to delete the value against index 'Jan'. Help her to choose the suitable option to do
so:
i. S1 = S1.drop(Jan)
ii. S1 = S1.drop('Jan')
iii. S1 = drop('Jan')
iv. S1 = S1.drop['Jan']
10. Which of the following Python statement can be used to rename the column 'Price' as 'MRP' of DF data
frame.
i. DF.rename({'Price' : 'MRP'}, axis = 1, inplace = 'True')
ii. DF.rename({'Price' : 'MRP'}, axis = 0, inplace = 'True')
iii. DF.rename({'Price' : 'MRP'}, axis = 0, inplace = True)
iv. DF.rename({'Price' : 'MRP'}, axis = 1, inplace = True)
11. Which of the following command will be used to find the sum of series S1 and S2?
i. print(sum(S1,S2))
ii. print(S1 + s2)
iii. print(S1.add(S2))
iv. print(s1 + s2)
12. Consider a given Series, M1.
Which of the following Python statement will create the series M1 (consider pandas module has been
imported)?
i. M1 = pandas.Series( [45,65,24,89], indexes = ['Term1', 'Term2', 'Term3', 'Term4'])
ii. M1 = pandas.Series( [45,65,24,89], index = ['Term1', 'Term2', 'Term3', 'Term4'])
iii. M1 = pandas.series( [45,65,24,89], Index = ['Term1', 'Term2', 'Term3', 'Term4'])
iv. M1 = pandas.series( [45,65,24,89], Indexes = ['Term1', 'Term2', 'Term3', 'Term4'])
13. _______ method is used to merge two data frames. (choose the correct option)
i. join()
ii. append()
iii. Append()
iv. Join()
14. Consider the following statements used by Sahin to create a Series S1:
______ pandas as pd #Statement 1
idx=['Mousin' , 'Kritika' , 'Kinshuk' , 'Ankit' , 'Shruti']
S1=pd.______ ([20000 , 50000 , 70000 , 100000 , 125000] , index = idx) #Statement 2
With reference to the above code answer the questions for (A) to (E).
(A) Choose the right code from the following for Statement 1.
i. Import
ii. import
iii. IMPORT
iv. Both i) and ii) are correct
(B) Choose the right code from the following for Statement 2.
i. pd.Series
ii. series
iii. Series
iv. DataFrame
(C) Which of the following command will display the series by adding 10 in each value.
i. print(S1 [+10])
ii. print(S1)+10
iii. print(S1+10)
iv. print(S1)+print(10)
(D) Choose the command that will give the following output:
i. print(S1[ : : -3])
ii. print(S1[-1:-5:-3])
iii. print(S1[[len(S1) -1,1]])
iv. All of the above
(E) Which of the following command will display the number of dimensions of the underlying data?
i. print(S1.shape)
ii. print(S1.ndim)
iii. print(S1.size)
iv. print(S1.elements)
15. Suman, a student of class XII, wants to store record of students with fields Name, Degree and Score.
For it, she wrote the following Python statements:
import pandas as pd
idx = [x for x in range(1,5)]
dict = { 'name':["Arpita", "Pratik", "Shreya", "Geeku"],
'degree': ["MBA", "BCA", "M.Tech", "MBA"],
'score':[ 90, 88, 98, 83]}
df = pd.DataFrame(dict, index = idx)
With reference to the above code answer the questions for (A) to (E).
(A) She wants to add a new record to this dataframe with index 5 and values ['Rahul','MCA',98].
Choose the correct statement for her to write for the same:
i. df.loc[5,:] = ['Rahul','MCA',98]
ii. df.loc[5] = ['Rahul','MCA',98]
iii. df.iloc[5] = [Rahul,MCA,98]
iv. Both i) and ii) are correct
(B) Suman wants to display Name and Degree of first 5 rows. But she was confused which of the
following command should she write. Help her choose the correct one.
a) df.head()[['name','degree']] b) df[['name','degree']].head()
c) df.head().loc[:,'name':'degree'] d) df.head().iloc[:,1:3]
i. Only a)
ii. Only a) and b)
iii. Only a), b) and c)
iv. All a), b), c) and d)
(C) Suman wants to display last 3 rows of the dataframe and for it, she wrote following command:
df.tail(). But she is getting wrong output. What mistake is she done?
i. She should write: df.tail(3)
ii. She should write: df.tail()
iii. She should write: df.tail3()
iv. She should write: df.tail()==3
(D) Suman wants to display rows 2 to 4 and columns name and score only, but she confused how to
write code for same. Help her in writing the code by choosing the correct answer from the
following:
i. df.loc[2:4,['name','score']]
ii. df.iloc[2:4,['name','score']]
iii. df.loc[2:4,'name':'score']
iv. df.iloc[2:4,'name':'score']
(E) Suman wants to display the details of the student who scores more than 80, but less than 90. Help
her to choose the correct statement for the same.
i. df.loc[df.score>80 & df.score<90]
ii. df.loc[(df.score>80) & (df.score<90)]
iii. df.loc[df.score>80 and df.score<90]
iv. df.loc[(df.score>80) and (df.score<90)]
16. Suhani has given the following command to delete a column 'pub' from a dataframe bookdf.
bookdf.drop(pub)
But she is not getting desired output, help her to select correct statement
i. book.dropdf(['pub'])
ii. book.dropdf(['pub'], axis=0])
iii. book.dropdf(['pub'], axis=1])
iv. None of the above
17. What type of error is returned by following statement?
import pandas as pnd
p=pnd.Series([1,2,3,4], index = list('abc'))
print(p)
i. NameError
ii. IndexError
iii. ValueError
iv. KeyError
18. What type of error is returned by following statement?
import pandas as pnd
p=pnd.Series([1,2,3,4], index = list('abcd'))
print(p['e'])
i. NameError
ii. IndexError
iii. ValueError
iv. KeyError
19. What type of error is returned by following statement?
import pandas as pnd
p=pnd.Series([1,2,3,4], index = list('abcd'))
print(p[e])
i. NameError
ii. IndexError
iii. ValueError
iv. KeyError
25. Mr. Patil is working in CBSE as data analyst. He uses Python Pandas for the same. He got a dataset of
the student of class XII appearing for AISSC Exam, 2021-2021 from some of the CBSE affiliated
schools. CBSE wants certain information from him, but he is facing some problems that still need to be
resolved. Kindly help them out.
Code:
import pandas as _______ #Statement 1
data={ "School":['KV' , 'AVS' , 'DPS' , 'APS' , 'ABV'],
"Place":['Duliajan' , 'Digboi' , 'Duliajan' , 'Namrup' , 'Dinjan'],
"Student":[400 , 300 , 450 , 350 , 480]}
df = pds. ________ (data) #Statement 2
print(df.head())
a) Choose the right code from the following for statement 1.
i. pd
ii. dp
iii. pds
iv. dps
b) Choose the right code from the following for statement 2.
i. Dictionary
ii. dataframe
iii. Series
iv. DataFrame
c) Choose the correct order of statement(s)/method(s) for the required output(s):
2 , 15 , (4,3) , False
i. print(df.ndim , df.size , df.shape , df.empty , end = ', ')
ii. print(df.ndim , df.size , df.shape , df.empty , sep = ' ' , end = ', ')
iii. print(df.ndim , df.size , df.shape , df.empty , sep = ',' , end = ' ')
iv. print(df.size , df.shape , df.ndim , df.empty , sep = ',' , end = ', ')
i) Mr. Patil had added a column (Code) at the end of the data frame. He now wants to remove it from the
data frame. Which of the following statement should he choose for it?
i. df.drop(['Code'],axis=1,inplace=True)
ii. df.pop('Code')
iii. del df['Code']
iv. Any one of the above
j) Help Mr. Patil to choose the correct statement for removing the row at index 7 permanently from the
data frame.
i. df.drop(['7'],axis=0,inplace=True)
ii. df.drop([7],axis=0,inplace=True)
iii. df.pop(7)
iv. Any one of the above
k) Help Mr. Patil to choose the correct statement to set the index of the data frame to S01, S02, S03, S04,
S05 and S06.
i. df.set_index(['S01' , 'S02' , 'S03' , 'S04' , 'S05' , 'S06'])
ii. df.rename_index(index = ['S01' , 'S02' , 'S03' , 'S04' , 'S05' , 'S06'])
iii. df.index = ['S01' , 'S02' , 'S03' , 'S04' , 'S05' , 'S06']
iv. df.rename_index(['S01' , 'S02' , 'S03' , 'S04' , 'S05' , 'S06'] , axis = 0)
l) Mr. Patil found that the data frame was indexed wrongly. He wants it to be as S03, S06, S01, S05, S04
and S02. Suggest him the correct statement.
i. df.reindex(['S03' , 'S06' , 'S01' , 'S05' , 'S04' , 'S02'] , axis = 0 , inplace = True)
ii. df.reindex(['S03' , 'S06' , 'S01' , 'S05' , 'S04' , 'S02'] , inplace = True)
iii. df=df.reindex(['S03' , 'S06' , 'S01' , 'S05' , 'S04' , 'S02'])
iv. Both i) and ii)
m) Suggest the correct statement to change the column name for Affiliation to AffCode:
i. df['Affiliation']=['AffCode']
ii. df.rename({'Affiliation':'AffCode'},inplace=True)
iii. df.rename(columns={'Affiliation':'AffCode'},inplace=True)
iv. df.rename(df['Affiliation']=df['AffCode'])
*********************