Skip to content
Exercises · Q7

Q.Using the Series created in Question 5, write commands for the following:

a) Find the dimensions, size and values of the Series EngAlph, Vowels, Friends, MTseries, MonthDays.
b) Rename the Series MTseries as SeriesEmpty.
c) Name the index of the Series MonthDays as monthno and that of Series Friends as Fname.
d) Display the 3rd and 2nd value of the Series Friends, in that order.
e) Display the alphabets 'e' to 'p' from the Series EngAlph.
f) Display the first 10 values in the Series EngAlph.
g) Display the last 10 values in the Series EngAlph.
h) Display the MTseries.
CBSENCERTSubjective· 5mImportance★★★★★
39% · 15/38 Questions
🔒 Locked · start free trial →

You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.

Start your 14-day free trial to unlock the full solution →

This question tests your ability to manipulate pandas Series objects — accessing attributes like .shape, .size, .values, renaming a Series, naming its index, slicing by position and by label, and using .head() / .tail().

The core idea here is that a Series is a one-dimensional labeled array. You can think of it as a column in a spreadsheet — it has both values (the data) and an index (the row labels). The question asks you to perform a variety of operations on several Series that were presumably created in Question 5. Since the actual creation commands from Question 5 are not given here, I will assume standard, sensible Series definitions that match the names and intended content. If your actual Series differ, the commands remain the same — just substitute the correct data.

Let me define the Series as they would reasonably be created:

import pandas as pd

# EngAlph: Series of English alphabets a-z
EngAlph = pd.Series(list('abcdefghijklmnopqrstuvwxyz'))

# Vowels: Series of vowels
Vowels = pd.Series(['a', 'e', 'i', 'o', 'u'])

# Friends: Series of friend names with default index
Friends = pd.Series(['Alice', 'Bob', 'Charlie', 'Diana', 'Eve'])

# MTseries: an empty Series
MTseries = pd.Series(dtype='float64')

# MonthDays: Series of month names and their days
MonthDays = pd.Series([31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31],
                      index=['Jan','Feb','Mar','Apr','May','Jun',
                             'Jul','Aug','Sep','Oct','Nov','Dec'])

Now let's answer each part.


(a) Find the dimensions, size and values of the Series EngAlph, Vowels, Friends, MTseries, MonthDays.

The dimensions of a Series is always 1 — it's one-dimensional. The .shape attribute returns a tuple (n,) where n is the number of elements. The size is the total number of elements (.size). The values are the underlying NumPy array (.values).

# For each Series
print("EngAlph dimensions:", EngAlph.shape)      # (26,)
print("EngAlph size:", EngAlph.size)              # 26
print("EngAlph values:", EngAlph.values)          # array(['a','b',...,'z'])

print("Vowels dimensions:", Vowels.shape)         # (5,)
print("Vowels size:", Vowels.size)                # 5
print("Vowels values:", Vowels.values)            # array(['a','e','i','o','u'])

print("Friends dimensions:", Friends.shape)       # (5,)
print("Friends size:", Friends.size)              # 5
print("Friends values:", Friends.values)          # array(['Alice','Bob',...])

print("MTseries dimensions:", MTseries.shape)     # (0,)
print("MTseries size:", MTseries.size)            # 0
print("MTseries values:", MTseries.values)        # array([], dtype=float64)

print("MonthDays dimensions:", MonthDays.shape)   # (12,)
print("MonthDays size:", MonthDays.size)          # 12
print("MonthDays values:", MonthDays.values)      # array([31,28,31,...])
Watch out

An empty Series like MTseries has .shape = (0,) and .size = 0. Its .values is an empty array. Do not confuse this with None or NaN.


(b) Rename the Series MTseries as SeriesEmpty.

Renaming a Series means assigning it to a new variable. The original variable name MTseries still exists unless you delete it. The cleanest way is:

SeriesEmpty = MTseries

If you also want to remove the old name:

SeriesEmpty = MTseries
del MTseries

But the question only asks to "rename" — in pandas, you simply assign the Series object to a new variable name.


(c) Name the index of the Series MonthDays as monthno and that of Series Friends as Fname.

The index of a Series has a .name attribute. You set it directly:

MonthDays.index.name = 'monthno'
Friends.index.name = 'Fname'

Now MonthDays will display with the index labeled monthno, and Friends with its index labeled Fname.

Tip

Setting the index name does not change the data — it only adds a label above the index column when you print the Series. This is purely cosmetic but useful for clarity in DataFrames.


(d) Display the 3rd and 2nd value of the Series Friends, in that order.

Remember: pandas uses zero-based indexing. The 1st value is at position 0, the 2nd at position 1, the 3rd at position 2. To display the 3rd value (index 2) followed by the 2nd value (index 1), you can use a list of positions:

print(Friends.iloc[[2, 1]])

Output:

2    Charlie
1        Bob
dtype: object
``` …

Unlock everything free for 14 days

  • Full step-by-step solutions
  • Concept-first explanations
  • Methods, shortcuts & mistakes
  • PYQ mapping + timed mock tests

Full access for 14 days. No credit card required.