You are on page 1of 8

INFORMATICS PRACTICES, 2023-24

ASSIGNMENT – 6

Pandas DataFrame (MCQ’s)


1. ____________ method in Pandas can be used to change the index of rows and
columns of a Series or Dataframe :
a) rename() b) reindex()
c) reframe() d) none of the above
2. The name “Pandas” is derived from the term:
a. Panel Data b. Panel Series
c. Python Document d. Panel Data Frame
3. The command to install the pandas is:
a. install pip pandas b. install pandas
c. pip pandas d. pip install pandas
4. Python pandas was developed by:
a. Guido van Rossum b. Travis Oliphant
c. Wes McKinney d. Brendan Eich
5. Pandas is a:
a. Package b. Language
c. Library d. Software
6. We can analyse the data in pandas with
a. Series b. Data Frame
c. Both of the above d. None of the above
7. Method or function to add a new row in a data frame is:
a. .loc() b. .iloc()
c. join d. add()
8. Which of the following import statement is not correct?
a. import pandas as class12 b. import pandas as 1pd
c. import pandas as pd1 d. import pandas as pd
9. While accessing the column from the data frame, we can specify the column
name. In case column does not exist, which type of error it will raise:
a. Key Error b. Syntax Error
c. Name Error d. Runtime Error
10. Function to display the first n rows in the DataFrame:
a. tail (n) b. head (n)
c. top (n) d. first (n)
11. Pandas data frame cannot be created using:
a. Dictionary of tuples b. Series
c. Dictionary of List d. List of Dictionaries
12. Which function will be used to read data from a CSV file into pandas data
frame?
a. readcsv() b. to_csv()

ASSIGNMENT - 6 (MCQ’s) AIR FORCE SCHOOL JORHAT Page 1 of 8


INFORMATICS PRACTICES, 2023-24
c. read_csv() d. csv_read()
13. Which of the following is not an attribute of pandas data frame?
a. length b. T
c. Size d. shape
14. What is a correct syntax to return the values of first row of a Pandas
DataFrame?
Assuming the name of the DataFrame is dfRent.
a. dfRent[0] b. dfRent.loc[1]
c. dfRent.loc[0] d. dfRent.iloc[1]
15. Which command will be used to delete 3 and 5 rows of the data frame. Assuming
the data frame name as DF.
a. DF.drop([2,4],axis=0) b. DF.drop([2,4],axis=1)
c. DF.drop([3,5],axis=1) d. DF.drop([3,5])
16. Ritika is a new learner for the python pandas, and she is aware of some
concepts of python. She has created some lists, but is unable to create the data
frame from the same. Help her by identifying the statement which will create
the data frame.
import pandas as pd
Name=['Manpreet','Kavil','Manu','Ria']
Phy=[70,60,76,89]
Chem=[30,70,50,65]

a. df=pd.DataFrame({"Name":Name,"Phy":Phy,"Chem":Chem})
b. d=("Name":Name,"Phy":Phy,"Chem":Chem) df=pd.DataFrame(d)
c. df=pd.DataFrame([Name,Phy,Chem],
columns=['Name',"Phy","Chem","Total"])
d. df=pd.DataFrame({Name:"Name", Phy :"Phy",Chem: "Chem"})
17. Assuming the given structure, which command will give us the given output:

Output Required: (3,5)


a. print(df.shape()) b. print(df.shape)
c. print(df.size) d. print(df.size())
18. Write the output of the given command:
df1.loc[:0,'Sal']
Consider the given dataframe.

ASSIGNMENT - 6 (MCQ’s) AIR FORCE SCHOOL JORHAT Page 2 of 8


INFORMATICS PRACTICES, 2023-24

a. 0 Kavita 50000 3000 b. 50000


c. 3000 d. 55000
19. Consider the following data frame name df :

Write the output of the given command:


print(df.marks/2)
a. 0 45.0 b. 0 45.0
1 NaN 1 NaN
2 43.5 2 43
Name: Marks, dtype: float64 Name: Marks, dtype: float64
c. 0 45 d. 0 45.0
1 NaN 1 0
2 43.5 2 43.5
Name: Marks, dtype: float64 Name: Marks, dtype: float64
20. Which method is used to Delete row(s) from DataFrame?
a. .drop() method b. .remove() method
c. .del() method d. .delete() method
21. Which of the following would give the same output as DF/DF1 where DF and DF1 are
DataFrames?
a. DF.div(DF1) b. Divide(DF,DF1)
c. DF1.div(DF) d. Div(DF,DF1)
22. Which of the following statement is wrong in context of DataFrame?
a. Two dimensional size is Mutable b. Can Perform Arithmetic operations
on rows and colomns
c. Homogeneous tabular data d. Create DataFrame from numpy
structure ndarray
23. Which attribute is not used with DataFrame?
a. Size b. Type
c. Empty d. columns
24. When we create a DataFrame from a list of Dictionaries the columns labels are
formed by the
a. Union of the keys of the b. Intersection of the keys of the
dictionaries dictionaries
c. Union of the values of the d. Intersection of the values of the
dictionaries dictionaries

ASSIGNMENT - 6 (MCQ’s) AIR FORCE SCHOOL JORHAT Page 3 of 8


INFORMATICS PRACTICES, 2023-24
25. Identify the correct option to select first four rows and second to fourth columns
from a DataFrame „Data‟
a. display(Data.iloc[1:4, 2:4])
b. display(Data.iloc[1:5, 2:5])
c. print(Data.iloc[0:4, 1:4])
d. print(Data.iloc[1:4, 2:4])
26. Sandhya wants to display the last four rows of the dataframe df and she has
written the following command:
df.tail()
But the first 5 rows are being displayed. To rectify this problem, which of the
following statements should be written?
a. df.head() b. df.last(4)
c. df.tail(4) d. df.rows(4)
27. Nowadays for developing Machine learning projects programmers rely on CSV
files rather than databases. Why?
a. csv can be used with proprietary b. csv files can be downloaded from
software only. open source websites free of cost.
c. csv files need not be imported d. csv is a simple and well formatted
while creating the projects. mode for data storage.
28. DataFrames can be created from?
a. Lists b. Dictionaries
c. Series d. All of the above
29. Consider the following statements-
Statement A : .loc() is a label based data selecting method to select a specific
row(s) or column(s) which we want to select.
Statement B : iloc() can not be used with default indics if customized indices
are provided.
a. Statement A is True but Statement B is False
b. Statement A is False but Statement B is True
c. Statement A and Statement B both are False
d. Statement A and Statement B both are True
30. Abhay is a student of class XII, and he is aware of some concepts of python. He has
created the DataFrame, but he is getting errors after executing the code. Help him by
identifying the correct statement that will create the DataFrame:
CODE:
import pandas as pd
stuname=[„Muskan‟,‟Radhika‟,‟Gopar‟,‟Pihu‟]
term1=[70,63,74,90]
term2=[67,70,86,95]
a. df=pd.DataFrame({“Name”:stuname, ”marks1”:term1, ”marks2”:term2})

b. df=pd.dataframe([stuname, term1,term2],
columns=[„stuName‟,”marks1”, “marks1”])
c. df=pd.DataFrame({stuname, term1,term2})
d. df=pd.dataframe({stuname, term1,term2})

ASSIGNMENT - 6 (MCQ’s) AIR FORCE SCHOOL JORHAT Page 4 of 8


INFORMATICS PRACTICES, 2023-24
31. Mr. Raman created a DataFrame from a Numpy array:
arr=np.array([[2,4,8],[3,9,27],[4,16,64]])
df=pd.DataFrame(arr, index=[„one‟,‟two‟, „three‟], ______)
Help him to add a customized column labels to the above DataFrame.
a. columns=‟no‟,‟sq‟,‟cube‟ b. column=[‟no‟,‟sq‟,‟cube‟]
c. columns=[‟no‟,‟sq‟,‟cube‟] d. columns=[[‟no‟,‟sq‟,‟cube‟]]
32. What will be the output of the following program
import pandas as pd
dic={'Name':['Sapna','Anmol','Rishul','Sameep'],
'Agg':[56,67,75,76],'Age':[16,18,16,19]}
df=pd.DataFrame(dic,columns=['Name','Age'])
print(df)
a. Name Agg Age b. Name Agg Age
101 Sapna 56 16 0 Sapna 56 16
102 Anmol 67 18 1 Anmol 67 18
103 Rishul 75 16 2 Rishul 75 16
104 Sameep 76 19 3 Sameep 76 19
c. Name d. Name Age
0 Sapna1 0 Sapna 16
1 Anmol 1 Anmol 18
2 Rishul 2 Rishul 16
3 Sameep 3 Sameep 19
33. Consider the following code -
import pandas as pd
S1=pd.Series([23,24,35,56], index=['a','b','c','d'])
S2=pd.Series([27,12,14,15], index=['b','y','c','ab'])
df=pd.DataFrame(S1+S2)
print(df)
a. 0 b. 0
a NaN a 50
ab NaN b 36
b 51.0 c 49
c 49.0 d 71
d NaN
y NaN

c. 0 d. 0
b 50 a NaN
y 36 ab NaN
c 49 b NaN
ab 71 c NaN
d NaN
y NaN
34. Sudhanshu has written the following code to create a DataFrame with Boolean index :
import numpy as np
import pandas as pd
df=pd.DataFrame (data=[[5,6,7]], index=[true,false,true])
print(df)
While executing the code, she is getting an error, help her to rectify the code:
a. df=pd.DataFrame([True,False,True], data=[5,6,7])

ASSIGNMENT - 6 (MCQ’s) AIR FORCE SCHOOL JORHAT Page 5 of 8


INFORMATICS PRACTICES, 2023-24
b. df=pd.DataFrame(data=[5,6,7], index=[True,False,True])
c. df=pd.DataFrame([true,false,true], data=[5,6,7])
d. df=pd.DataFrame(index=[true,false,true], data=[[5,6,7]])
35. Sushila has created a DataFrame with the help of the following code:
import pandas
EMP={'EMPID':['E01','E02','E03','E04','E05'],
'EMPNAME':['KISHORI','PRIYA','DAMODAR','REEMA','MANOJ'],
'EMP_SALARY':[67000,34000,68000,90000,43000]}
df=pandas.DataFrame(EMP, index=['001','002','003','004','005'])
print(df.loc[0:3:,:])
and she wants to get the following output –
EMPID EMPNAME EMP_SALARY
001 E01 KISHORI 67000
002 E02 PRIYA 34000
003 E03 DAMODAR 68000
Help her to correct the code –
a. print(df.iloc['001':'003',:])
b. print(df.loc['001':'003',:])
c. print(EMP[0:3,:])
d. print(df.loc['001':'004',:])
36. Which of the following statement will import pandas library?
a. Import pandas as pd b. import Pandas as py
c. import pandas as pd d. import panda as pd
37. Which of the following can be used to specify the data while creating a
DataFrame?
a. Series b. List of Dictionaries
c. Structured ndarray d. All of these
38. Assertion (A):- DataFrame has both a row and column index.
Reasoning (R): - A DataFrame is a two-dimensional labelled data structure like
a table of MySQL.
a. Both A and R are true and R is the correct explanation for A
b. Both A and R are true and R is not the correct explanation for A
c. A is True but R is False
d. A is false but R is True

39. Given the following dictionaries.


dict_exam={"Exam":"AISSCE", "Year":2023}
dict_result={"Total":500, "Pass_Marks":165}
Which statement will merge the contents of both dictionaries?
a. dict_exam.update(dict_result)
b. dict_exam + dict_result
c. dict_exam.add(dict_result)
d. dict_exam.merge(dict_result)
40. Which of the following is a two-dimensional labelled data structure of Python ?

ASSIGNMENT - 6 (MCQ’s) AIR FORCE SCHOOL JORHAT Page 6 of 8


INFORMATICS PRACTICES, 2023-24
a. Relation b. Dataframe
c. Series d. Square
41. CSV stands for:
a. Column Separated Value b. Class Separated Value
c. Comma Separated Value d. None of the above
42. Which attribute of a dataframe is used to convert row a into columns and columns into rows
in a dataframe?
a. T b. ndim
c. empty d. shape
43. Assertion (A): Nidhi has create dataframe Df1. She can expand or delete any row /column
in this dataframe.
Reason(R): In python DataFrame objects can be concatenated or merged.
a. Both A and R are true and R is the b. Both A and R are true but R is not the
correct explanation of A. correct explanation of A.
c. A is true but R is false. d. A is false but R is true.
44. Assertion (A): sorting is the operation to arrange data in a specific order , sort_values ()
function used to perform the operation
Reasoning (R): Row wise shorting cannot be performed in python dataframe objects
a. Both A and R are true and R is the b. Both A and R are Ture and R is not the
correct explanation of A. correct explanation of R .
c. A is True but R is false. d. Both A and R are false
45. Assertion (A): Boolean indexing is a type of indexing.
Reasoning (R) : DataFrame.loc(False) function can be used to find the relative values where
index value is False
a. Both A and R are true and R is the b. A is true but R is false.
correct explanation of A.
c. A is false but R is true d. Both A and R are false
46. Assertion (A): Some time we want to combine the two dataframes using the merge()
function
Reasoning (R): Merging operation can be performed only with common values of column
not with specific column
a. Both A and R are true and R is the b. A is true but R is false.
correct explanation of A.
c. A is false but R is true d. Both A and R are false
47. Ms. Kavitha wants to print a single column from the dataframe, which of the following is
correct syntax for her?
a. df(col) b. df<col>
c. df[col] d. df{df:col}
48. Complete the given Python code to get the required output as:
import pandas as pd
data ={"Marks1":[80,84,90], "Marks2":[82,78,95],
"Marks3":[90,94,97]}
df= pd.DataFrame(data, ______=['R1','R2','R3'])
print(df)

Output:

ASSIGNMENT - 6 (MCQ’s) AIR FORCE SCHOOL JORHAT Page 7 of 8


INFORMATICS PRACTICES, 2023-24
Marks1 Marks2 Marks3
R1 80 82 90
R2 84 78 94
R3 90 95 97
a. index b. columns
c. col d. heads
49. Complete the given Python code to get the required output as:
import pandas as pd
dic={'Name':['Sapna','Anmol','Rishul','Sameep'],
'Agg':[56,67,75,76],'Age':[16,18,16,19]}
df=pd.DataFrame(dic,________=['Name','Age'])
print(df)

Output:
Name Age
0 Sapna 16
1 Anmol 18
2 Rishul 16
3 Sameep 19

a. index b. columns
c. col d. heads
50. Complete the given Python code to get the required output as:
import pandas as pd
df1= pd.DataFrame(["First","Second"],columns=['Col'])
df2= pd.DataFrame(["Third","Fourth"],columns=['Col'])
df = pd.________([df2, df1], axis=0, ignore_index=True)
print(df)

Output:
Col
0 Third
1 Fourth
2 First
3 Second
a. loc b. iloc
c. concat d. merge

ASSIGNMENT - 6 (MCQ’s) AIR FORCE SCHOOL JORHAT Page 8 of 8

You might also like