Attachment

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

M.E.

S INDIAN SCHOOL, DOHA - QATAR


Worksheet-5 2024- 2025

Section : BOYS’/GIRLS Date : 25/4/2024


Class & Div. : XII(ALLDIVISIONS) Subject : IP

Lesson / Topic: Data Handling using Pandas – I (Dataframe)


xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
1. In a DataFrame, Axis= 1 represents the_____________ elements.
a. row b.all
c.column d.none of the above

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

4. Consider a code df=pd.DataFrame([2,4,5,9],index=[True,False,False,True])


Which of the following is used to create the above dataframe?
(a) Created using Series (b) Created using List of Dictionary
(c) Created using Boolean indexing (d) Created using Strings

5. CSV stands for:


(a) Common Standard Values (b) Comma Semicolon Values
(c) Comma Separated Values (d) Comma Spreadsheet Values

6. Difference between loc() and iloc().


(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.

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.

10. Which method is used to delete row or column in DataFrame?


a. delete( ) b. del( )
c. drop( ) d. None of the above

11. In DataFrame, by default new column added as the _________ column


a. First (Left Side) b. Second
c. Last (Right Side) d. Random

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

14. We can create DataFrame from _____


a. Numpy arrays b. List of Dictionaries
c. Dictionary of Lists d. All of the above

15. DF[ : ] = 65 , will set __________ values of a DataFrame ‘DF’ to 65.


a. First row b. First column.
c. All. 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

You might also like