Attachment
Attachment
Attachment
2. What is the correct syntax to return both the first row and the second row in a Pandas DataFrame df?
(a) df.loc[0,1] (b) df.[[0,1]]
(c) df.loc[[0-1]] (d) df.loc[[0,1]]
3. If a Dataframe is created using a 2D dictionary, then the indexes/row labels are formed from
(a) dictionary's values (b) inner dictionary's keys
(c) outer dictionary's keys (d) none of these
7. Which command will be used to delete 3 and 5 columns 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])
8. Nikita is working in an IT company. She is trying to store details of 5 employees in a dataframe. She has
collected data and stores it in different lists but is facing problem in creating a dataframe. She has given the
following command but is not getting the desired output. Help her.
import pandas as pd
EmpName=['Rohit','Vinay','Sahil','Kailash','Dipika']
Desig=['Manager','Sales Head','IT Manager','Markeing head','Admin Head']
Salary =[50000,40000,70000,55000,35000] data={EmpName,Desig,Salary}
Record=pd.DataFrame(data)
print(Record)
(i) data=[EmpName,Desig,Salary]
(ii) data={Name:EmpName,Designation:Desig,Salary:Salary}
(iii) data={'Name':EmpName,'Designation':Desig,'Salary':Salary}
(iv) data=[‘EmpName’,’Desig’,’Salary’]
9. Consider the two statements given below:
Statement 1: The missing data in Pandas is represented by NaN.
Statement 2: NaN is equivalent to 0.
(a)Both statements are true.
(b) Both statements are false.
(c)Statement 1 is true but Statement 2 is false.
(d) Statement 2 is true but Statement 1 is false.
12. In given code dataframe ‘D1’ has _____ rows and ______ columns.
import pandas as pd
LoD = {“Name” : [“Amit”, “Anil”,”Ravi”], “RollNo” : [1,2,3]}
D1 = pd.DataFrame(LoD)
a. 3, 3 b. 3, 2
c. 2, 3 d. None of the above
13. When we create DataFrame from List of Dictionaries, then number of columns in DataFrame is equal to
the __
a. maximum number of keys in first dictionary of the list
b. maximum number of different keys in all dictionaries of the list
c. maximum number of dictionaries in the list
d. None of the above
16. Aman is trying to extract rows from a DataFrame “DF” using following command.
DF.loc[0:4]
How many rows will be extracted from DataFrame?
a. 4 b. 5
c. 6 d. 0
17. Given a Pandas dataframe called HEAD, the command which will display the first 3 rows is ______.
(A) print(HEAD.head(3)) (B) print(HEAD.Heads(3))
(C) print(HEAD.heads(3)) (D) print(head.HEAD(3))
18. Assertion (A): DataFrame has both a row and column index.
Reasoning (R): .loc() is a label based data selecting method to select a specific row(s) or column(s)
which we want to select.
(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
19. In Pandas which of the following dataframe attribute can be used to know the number of rows and
columns in a dataframe
a. size b. index
c. count d. shape
20. Assertion (A):- While creating a dataframe with a nested or 2D dictionary, Python interprets the outer dict keys
as the column index and the inner keys as the row indices.
Reasoning (R):- A column can be deleted using remove command.
(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
******************************************************************************************
F 061, Rev 01, dtd 10th March 2020