This practice paper is designed in such a way that it covers all the questions like MCQs, True/False, Theory Questions, Coding Questions as well as Output Question as per the CBSE Syllabus. By practicing it students will learn different types of questions related to Series and gain more confidence to write the answers in board exams.
I have already explained series creation practice problem in my previous practice paper Python Series Practice Questions with Solutions (Part-I). You will practice more questions based on Series with Python Series Practice Question with Solutions (Part-II)
SECTION-I Multiple Choice Questions
1. To create any kind of Series object, which method you may use: |
a) Pandas |
b) Series |
c) Both (a) and (b) |
d) none of these |
Answer : option b) Series() is a method which is use to create Series Object. However, Pandas is a library, so, to use series() method, we should import Pandas library. |
2. To get total number of elements of a series, you may use |
a) len() |
b) count() |
c) Both (a) and (b) |
d) none of these |
Answer : option a) len() |
3. To display last 5 rows of a Series object S, you may use: |
a) S.tail() |
b) S.head(6) |
c) S.head(0:4) |
d) none of these |
Answer : option a) S.tail() |
4. Missing data in Pandas object is represented through |
a) Null |
b) None |
c) Missing |
d) NaN |
Answer : option d) NaN |
5. The data label associated with a particular value of Series is called its…………. |
a) Data Value |
b) Index |
c) Value |
d) None of the above |
Answer : option b) index |
SECTION-II State True/False
1. A Series is a 1-Dimensional object that can hold any data type such as integers, floats and strings. |
Answer : True. |
2. A series has only one axis. |
Answer : True. |
3. A series object is value mutable |
Answer : True. |
4. Series object’s indexes are always from 0 to n-1 |
Answer : False. Series can have any custom index. |
5. You cannot change the index of Series’s object. |
Answer: False. |
SECTION-III Answers the following questions
1. Write command to print the following details of a Series object “study” | ||||||||||||||||||||||||||||||
a) if the series is empty. | ||||||||||||||||||||||||||||||
Answer : study.empty : “empty” is a series attribute which return True if the Series object is empty. | ||||||||||||||||||||||||||||||
b) indexes of the series | ||||||||||||||||||||||||||||||
Answer : study.index : “index” is a series attribute which return label of a series object. | ||||||||||||||||||||||||||||||
c) the datatype of the underlying data | ||||||||||||||||||||||||||||||
Answer : study.dtype : “dtype” is a series attribute which return data type of the series object. | ||||||||||||||||||||||||||||||
d) If the series stores any NaN values. | ||||||||||||||||||||||||||||||
Answer : study.hasnans : “hasnans” is a series attribute which return True if there are any NaN values. | ||||||||||||||||||||||||||||||
2. Given the following series objects:
| ||||||||||||||||||||||||||||||
a) What will be the result of S1+S2. | ||||||||||||||||||||||||||||||
Answer : Arithmetic Operation in Series works on index, so, be careful when you will add two series objects.
| ||||||||||||||||||||||||||||||
b) What will be the result of S1-S2. | ||||||||||||||||||||||||||||||
Answer : Arithmetic Operation in Series works on index, so, be careful when you will add two series objects.
| ||||||||||||||||||||||||||||||
3. A series object “S8” stores the bonus of different employees, like:
| ||||||||||||||||||||||||||||||
a) Write a statement to create the above series | ||||||||||||||||||||||||||||||
Answer : | ||||||||||||||||||||||||||||||
b) Write a statement to display all employees who are getting salary more than 6000. | ||||||||||||||||||||||||||||||
Answer : | ||||||||||||||||||||||||||||||
5. Consider a series object “study”, created using the following statements: study=pd.Series([11,23,31,61,87,93], index=[‘a’,’b’,’c’,’d’,’e’,’f’]) Based on the series object, write statements to do the following: | ||||||||||||||||||||||||||||||
a) Retrieve the third element and print it. | ||||||||||||||||||||||||||||||
Answer: study[‘c’] | ||||||||||||||||||||||||||||||
b) Retrieve and print the first three elements | ||||||||||||||||||||||||||||||
Answer : print(study[:3]) or print(study[‘a’:’c’]) or print(study.head(3)) | ||||||||||||||||||||||||||||||
c) Retrieve and print the last two elements | ||||||||||||||||||||||||||||||
Answer : print(study.tail(2)) | ||||||||||||||||||||||||||||||
d) Retrieve and print alternate elements, starting from index ‘b’ | ||||||||||||||||||||||||||||||
Answer : print(study[‘b’::2]) | ||||||||||||||||||||||||||||||
e) Retrieve and print all elements where value is even | ||||||||||||||||||||||||||||||
Answer : print(study[study%2==0]) | ||||||||||||||||||||||||||||||
5. Create a series with 5 elements, then find square of each even elements and find cube of each odd elements. | ||||||||||||||||||||||||||||||
Answer : |
SECTION-IV Write the code for the following questions :
a) Create a Series with 5 values and indexes, then: a) Sort the series element by descending order of elements. | ||||||||||||||||||
Answer : | ||||||||||||||||||
b) Sort the series index by ascending | ||||||||||||||||||
Answer : | ||||||||||||||||||
2. Difference between Series and DataFrame. | ||||||||||||||||||
Answer : In the Python data analysis library, Pandas, the difference between a DataFrame and a Series can be thought of in the following way:
Here is a comparison of DataFrame and Series in tabular form:
| ||||||||||||||||||
3. Write any one difference between list and series. | ||||||||||||||||||
Answer : In Python, both lists and Series are used to store sequences of data, but there are some key differences between them:
So, in short, lists are general-purpose data structures that can store elements of any data type and can be used for a wide range of purposes, while Series are specifically designed for efficient data analysis and manipulation in the Pandas library. |