0% found this document useful (0 votes)
57 views6 pages

Class 12 - Ip - Worksheets - Pandas1

Uploaded by

gt
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
57 views6 pages

Class 12 - Ip - Worksheets - Pandas1

Uploaded by

gt
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

2023-2024

NAME: SUBJECT: IP
CLASS: XII CHAPTER NAME: Pandas 1
DATE: WORK SHEET NO:

I. MULTIPLE CHOICE QUESTIONS

1. To create an empty Series object, you can use:


a) pd.Series(empty)
b) pd.Series(np.NaN)
c) pd.Series()
d) all of these

2. To get the number of dimensions of a series object, __________attribute is displayed.


a) Index
b) Size
c) itemsize
d) ndim

3. To display last five rows of a series object s, you may write_____________.


a) head()
b) head(5)
c) tail()
d) tail(5)

4. ___________ Pandas object grow in size.


a) DataFrame
b) Series
c) Panel
d) None of these

5. The axis 0 identifies a dataframe’s___________


a) rows
b) columns
c) values
d) datatype

6. To change the 5th column ‘s value at 3rd row as 35 in dataframe DF,you can write
a) DF[4,6]=35
b) Df[3,5]=35
c) DF.iat[4,6]=35
d) DF.iat[3,5]=35

7. Which among the following options can be used to create a Dataframe in Pandas?
a) A scalar value
b) An ndarray
c) A python dict
d) All of these
8. To add two dataframes’ values, _____________function may be used.
a) plus
b) rplus
c) add
d) radd

9. To subtract the values of two dataframes,____________function may be used.


a) sub
b) difference
c) minus
d) rsub

10. The following statement will____________


df=df.drop([‘Name’,’class’,’rollno’],axis=1)
a) Delete three columns having labels ‘Name’, ‘Class’ and ‘Rollno’
b) Delete three rows having labels ‘Name’,class’ and ‘Rollno’
c) Delete any three columns
d) Return error

2023-2024
NAME: SUBJECT: IP
CLASS: XII CHAPTER NAME: Pandas 1
DATE: WORK SHEET NO:

I) MULTIPLE CHOICE QUESTIONS

16. What is a Series in pandas?

a) A two-dimensional labeled data structure


b) A one-dimensional labeled array capable of holding any data type
c) A collection of key-value pairs
d) A database table in pandas

2. How do you create a Series in pandas?

a) Using the pd.DataFrame constructor


b) Using the pd.Series constructor
c) Using the pd.array constructor
d) Using the pd.list constructor

3. How can you access the elements of a Series by label?


a) Using integer indices
b) Using boolean indexing
c) Using labels or index
d) By using only integer labels

4. What is the default index for a Series if not specified?

a) 0, 1, 2, ...
b) 1, 2, 3, ...
c) 'a', 'b', 'c', ...
d) None of the above

5. Which of the following operations can be performed on a Series?

a) Mathematical operations like addition and subtraction


b) Logical operations like AND and OR
c) String operations like concatenation
d) All of the above

6. How can you check if a label is present in a Series?

a) Using the in operator


b) Using the exists method
c) Using the contains method
d) Using the is present method

7. What is the purpose of the dtype attribute in a Series?

a) It specifies the data type of the index


b) It specifies the data type of the values in the Series
c) It specifies the data type of both index and values
d) It is not used in pandas Series

8. How can you change the index of a Series?

a) Using the set_index method


b) Using the reset_index method
c) Using the reindex method
d) All of the above

9. What is the result of adding two Series with different indices?

a) The sum will contain only the common indices


b) The sum will contain all indices, filling missing values with NaN
c) An error will be raised
d) The sum will contain only the indices of the first Series

10. How can you drop elements from a Series with specific labels?

a) Using the remove method


b) Using the delete method
c) Using the drop method
d) Using the discard method

11. What will be output for the following code?


import pandas as pd
s=pd.Series ([1, 2, 3, 4, 5], index= [‘a’,’b’,’c’,’d’,’e’])
print(s[‘a’])

a) 1
b) 2
c) 3
d) 4

12. What will be the output for the following code?


import pandas as pd
import numpy as np
S=pd.Series (np.random.randn (2))
Print (s.size)

a) 0
b) 1
c) 2
d) 3

2023-2024
NAME: SUBJECT: IP
CLASS:XII CHAPTER NAME: Pandas 1
DATE: WORK SHEET NO:

I. CASE BASED QUESTIONS:

Case 1: Exam Scores


Consider a DataFrame named exam_scores containing information about students, with columns
'StudentID', 'Name', 'Subject', and 'Score'.
1. Question: How can you select the scores of students with IDs 101, 105, and 110?
a) exam_scores.loc[['101', '105', '110'], 'Score']
b) exam_scores.iloc[[0, 4, 9], 3]
c) exam_scores.loc[[101, 105, 110]]['Score']
d) exam_scores.iloc[[101, 105, 110], 'Score']
2. Question: If you want to select the scores of all students in the 'Math' subject, how would you do
it?
a) exam_scores.loc[exam_scores['Subject'] == 'Math', 'Score']
b) exam_scores.iloc[exam_scores['Subject'] == 'Math', 3]
c) exam_scores.loc['Math', 'Score']
d) exam_scores.iloc[exam_scores['Subject'] == 'Math']['Score']

Case 2: Employee Data


Consider a DataFrame named employee_data with columns 'EmployeeID', 'Name', 'Department',
and 'Salary'.
3. Question: How can you select the information for employees with IDs 201 to 210?
a) employee_data.loc[201:210]
b) employee_data.iloc[200:210]
c) employee_data.loc[200:209]
d) employee_data.iloc[201:210]

4. Question: If you want to select the salary of an employee with ID 205, how would you do it?
a) employee_data.loc[205, 'Salary']
b) employee_data.iloc[205, 'Salary']
c) employee_data.loc[employee_data['EmployeeID'] == 205, 'Salary']
d) employee_data.iloc[employee_data['EmployeeID'] == 205, 3]

Case 3: Temperature Data


Suppose you have a DataFrame named temperature_data containing columns 'Date', 'City', and
'Temperature'.
5. Question: How can you select the temperatures recorded in cities 'A', 'B', and 'C'?
a) temperature_data.loc[temperature_data['City'].isin(['A', 'B', 'C']), 'Temperature']
b) temperature_data.iloc[temperature_data['City'] in ['A', 'B', 'C'], 2]
c) temperature_data.loc[['A', 'B', 'C'], 'Temperature']
d) temperature_data.iloc[[0, 1, 2], 'Temperature']
6. Question: If you want to select the temperature recorded on '2022-01-15' in all cities, how would
you do it?
a) temperature_data.loc['2022-01-15', 'Temperature']
b) temperature_data.iloc[temperature_data['Date'] == '2022-01-15', 'Temperature']
c) temperature_data.loc[temperature_data['Date'] == '2022-01-15']['Temperature']
d) temperature_data.iloc[temperature_data['Date'] == '2022-01-15']['Temperature']

II. ASSERTION AND REASONING:

Question 1: Assertion: Using loc with integer values will raise an error.
Reasoning: loc is designed for label-based indexing, and using integer values
with loc may lead to unexpected results or errors.
a) Both Assertion and Reasoning are true, and Reasoning is the correct explanation for Assertion.
b) Both Assertion and Reasoning are true, but Reasoning is not the correct explanation for
Assertion.
c) Assertion is true, but Reasoning is false.
d) Assertion is false.

Question 2: Assertion: When using iloc, a single integer value can be used to select a specific row.
Reasoning: iloc allows for integer-location based indexing, making it suitable for
Selecting specific rows using integer indices.
a) Both Assertion and Reasoning are true, and Reasoning is the correct explanation for Assertion.
b) Both Assertion and Reasoning are true, but Reasoning is not the correct explanation for
Assertion.
c) Assertion is true, but Reasoning is false.
d) Assertion is false.

You might also like