Question:medium

Write a Python program to create and display a Pandas Series as shown below:

July31
Aug31
Sept30
Oct31

The index labels are the names of the months – July, Aug, Sept, Oct.

The corresponding scalar values are the number of days in these respective months – 31, 31, 30, 31.

Show Hint

Import pandas and call pd.Series with the list [31, 31, 30, 31] and the index list of month names, then print it.
Updated On: Oct 20, 2026
Show Solution

Solution and Explanation

Step 1: Choose how to hold the data:
Each month name goes with one number of days. A Python dictionary stores exactly such pairs, so it is a natural choice. When a dictionary is given to pd.Series, the keys become the index and the values become the data.

Step 2: Build the dictionary:
The keys are the month names and the values are the day counts.
days = {'July': 31, 'Aug': 31, 'Sept': 30, 'Oct': 31}

The order of the pairs is kept, so the output rows follow July, Aug, Sept, Oct.

Step 3: Create and show the Series:
import pandas as pd
days = {'July': 31, 'Aug': 31, 'Sept': 30, 'Oct': 31}
S = pd.Series(days)
print(S)


Step 4: Output checked by running the code:
July    31
Aug     31
Sept    30
Oct     31
dtype: int64

This is the same Series as the one in the question.

Final Answer:
pd.Series(days) with the dictionary above creates the Series, and print(S) displays it. Passing the two lists with index= also gives the same result.
Was this answer helpful?
0