Here are some MCQ questions based on Pandas Series:
Basic Pandas Series MCQs:
What is a Pandas Series in Python?
- a) A 2D array-like structure with rows and columns
- b) A 1D labeled array capable of holding data of any type
- c) A collection of tables
- d) A list of dictionaries
- Answer: b) A 1D labeled array capable of holding data of any type
Which of the following is the correct way to create a Pandas Series from a list in Python?
pythondata = [10, 20, 30, 40]
- a)
s = pd.Series([data])
- b)
s = pd.Series(data)
- c)
s = pd.DataFrame(data)
- d)
s = pd.array(data)
- Answer: b)
s = pd.Series(data)
- a)
Which of the following can be used as valid data types for a Pandas Series?
- a) Lists
- b) NumPy arrays
- c) Dictionaries
- d) All of the above
- Answer: d) All of the above
By default, what does the index of a Pandas Series start with?
- a) 0
- b) 1
- c) -1
- d) The index must be explicitly defined
- Answer: a) 0
How can you access the first element of a Pandas Series
s
?- a)
s[0]
- b)
s.first()
- c)
s[1]
- d)
s.head()
- Answer: a)
s[0]
- a)
How can you get the index labels of a Pandas Series?
- a)
s.values
- b)
s.index
- c)
s.labels
- d)
s.columns
- Answer: b)
s.index
- a)
What method would you use to return the first 3 rows of a Pandas Series
s
?- a)
s.tail(3)
- b)
s.head(3)
- c)
s.first(3)
- d)
s.top(3)
- Answer: b)
s.head(3)
- a)
Which method is used to return the underlying data of a Pandas Series as a NumPy array?
- a)
s.index
- b)
s.array()
- c)
s.to_numpy()
- d)
s.index.values
- Answer: c)
s.to_numpy()
- a)
What does the
dtype
attribute of a Pandas Series return?- a) The data type of the values stored in the Series
- b) The length of the Series
- c) The index labels
- d) The name of the Series
- Answer: a) The data type of the values stored in the Series
What happens when you try to add two Pandas Series with different index values?
- a) Raises an error
- b) Automatically aligns the Series based on their indexes and adds the corresponding values
- c) Only adds the values from the first Series
- d) Only adds the values from the second Series
- Answer: b) Automatically aligns the Series based on their indexes and adds the corresponding values
Advanced Pandas Series MCQs:
How can you give a Pandas Series a name?
- a) Using the
rename()
method - b) Assigning a value to the
name
attribute - c) Using the
set_name()
method - d) Using the
Series()
constructor with thename
parameter - Answer: b) Assigning a value to the
name
attribute
- a) Using the
Which method would you use to sort a Pandas Series by its index?
- a)
s.sort()
- b)
s.sort_values()
- c)
s.order()
- d)
s.sort_index()
- Answer: d)
s.sort_index()
- a)
How would you check for missing values (NaN) in a Pandas Series
s
?- a)
s.check_na()
- b)
s.isnull()
- c)
s.isnan()
- d)
s.empty()
- Answer: b)
s.isnull()
- a)
What will the following code return?
pythons = pd.Series([10, 20, None, 30]) s.notnull()
- a) A Series of boolean values indicating if the data is not missing
- b) The first non-null value
- c) A list of non-null values
- d) An error
- Answer: a) A Series of boolean values indicating if the data is not missing
Which function is used to return the descriptive statistics of a Pandas Series? (outofsyllabus)
- a)
s.describe()
- b)
s.stats()
- c)
s.details()
- d)
s.summary()
- Answer: a)
s.describe()
- a)
How can you change the index of a Pandas Series?
- a) Using the
index
method - b) Using the
set_index()
method - c) Directly assigning a new index using
s.index = new_index
- d) Using the
reindex()
method - Answer: c) Directly assigning a new index using
s.index = new_index
- a) Using the
How can you check if a specific label is present in a Pandas Series?
- a)
label in s
- b)
s.label_exists(label)
- c)
s.index.has_label(label)
- d)
s.contains(label)
- Answer: a)
label in s
- a)
Which of the following functions can be used to append data to a Pandas Series? (outofsyllabus)
- a)
append()
- b)
concat()
- c)
extend()
- d)
merge()
- Answer: a)
append()
- a)
What will the following code return?
pythons = pd.Series([10, 20, 30]) s + 5
- a)
[15, 25, 35]
- b) A new Series with 5 added to each value
- c) A new Series with values multiplied by 5
- d) An error
- Answer: b) A new Series with 5 added to each value
- a)
Which method is used to return the unique values in a Pandas Series?
- a)
s.unique()
- b)
s.distinct()
- c)
s.drop_duplicates()
- d)
s.values_unique()
- Answer: a)
s.unique()
- a)
What will the following code do?
pythons = pd.Series([10, 20, 30], index=['a', 'b', 'c']) s['b']
- a) Return 10
- b) Return 20
- c) Return ['a', 'b', 'c']
- d) Raise an error
- Answer: b) Return 20
How can you filter a Pandas Series
s
to show values greater than 15?- a)
s > 15
- b)
s.filter(15)
- c)
s[s > 15]
- d)
s.greater(15)
- Answer: c)
s[s > 15]
- a)
What does the
counts()
method of a Pandas Series return?- a) A count of unique values in the Series
- b) The total number of elements in the Series
- c) The number of missing values in the Series
- d) The sum of all the values in the Series
- Answer: a) A count of unique values in the Series
Which of the following can be used to handle missing values in a Pandas Series?
- a)
fillna()
- b)
dropna()
- c) Both a and b
- d)
drop_duplicates()
- Answer: c) Both a and b
- a)
How can you rename the index of a Pandas Series
s
?- a)
s.set_index(new_index)
- b)
s.rename_index(new_index)
- c)
s.index = new_index
- d)
s.reset_index(new_index)
- Answer: c)
s.index = new_index
- a)
Which of the following methods can you use to return the sum of all elements in a Pandas Series?
- a)
s.add()
- b)
s.sum()
- c)
s.count()
- d)
s.values.sum()
- Answer: b)
s.sum()
- a)
What will the following code do?
pythons = pd.Series([1, 2, 3, 4, 5]) s[1:4]
- a) Return the first four values of the Series
- b) Return the second to fourth values of the Series
- c) Return the second, third, and fourth values (index positions 1 to 3)
- d) Raise an error
- Answer: c) Return the second, third, and fourth values (index positions 1 to 3)
How can you check if a Pandas Series is empty?
- a)
s.empty()
- b)
s.is_empty()
- c)
s.empty
- d)
len(s) == 0
- Answer: c)
s.empty
- a)
0 Comments
Please do note create link post in comment section