Q.(a) Niharika wants to create a Pandas Series using a NumPy array with three elements 'a', 'b', and 'c', and assign custom indexes 'first', 'second' and 'third'. Help her complete the code below. import pandas as pd import ______ as np arr = np._____ (['a' , 'b' , 'c']) s = pd.(arr,=['first','second','third']) print(s)
🔒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 →Part (a)Concept understanding — Pandas Series Creation
Imagine you have a messy desk with loose notes, receipts, and to-do lists scattered everywhere. Now imagine you take a single strip of paper, write one item on each line in a fixed order, and label the strip "Monday's Expenses." That strip is a Pandas Series — a single column of data with a label for each row.
A Pandas Series is the simplest building block in the Pandas library for Python. It is a one-dimensional array that can hold any type of data — numbers, text, dates, or even mixed types — and it comes with an index, which is like a row number or a custom label for each entry. Think of it as a smart list that remembers the name of each item.
A Series is not a table or a spreadsheet. It is just one column of data, with an index on the left and values on the right. If you have ever used a dictionary in Python, a Series is similar — keys on the left, values on the right — but with extra powers like sorting, filtering, and mathematical operations.
Why does this matter for a commerce or humanities student?
In your work, you will often deal with lists of things: monthly sales figures, student names in a class, dates of transactions, or categories of expenses. A Series lets you store that list in a structured way so you can quickly find, sort, or analyse it. For example, if you have a list of daily footfall in a store, a Series lets you label each day (Monday, Tuesday, …) and then instantly ask: "Which day had the highest footfall?" or "What was the average footfall on weekends?"
How is a Series created?
You can create a Series from several everyday sources:
- From a Python list: You give Pandas a simple list of values, and it automatically assigns numeric indices (0, 1, 2, …) just like the rows in a notebook.
- From a Python dictionary: The dictionary keys become the index labels, and the values become the data. This is very natural — you already think in key-value pairs (e.g., "January": 45000, "February": 52000).
- From a single value: You can create a Series where every entry is the same value, repeated a certain number of times — useful for setting a default or a constant.
- From a NumPy array (if you have done some data science): but for a first meeting, the list and dictionary methods are the most intuitive.
The index is the backbone of a Series. Without an index, you just have a plain list. With an index, you can label your data meaningfully — dates, names, categories — and perform operations that respect those labels. For instance, adding two Series with the same index will align them by label, not by position.
A concrete mental picture …
Part (b)Concept understanding — Series Operations
Series Operations: A First Look
Think of a series as a queue. You have a set of items—dates, names, amounts, events—arranged one after another in a definite order. Series operations are simply the things you can do with that queue: you can add something to the front, remove something from the back, rearrange the order, or compare two queues to see if they match.
In everyday life, you already perform series operations without thinking. When you sort your playlist by artist, you are reordering a series. When you add a new contact to the top of your phone's list, you are inserting at the beginning. When you check whether two shopping lists are identical, you are comparing two series element by element.
The Precise Meaning
A series is a sequence of items where the position of each item matters. The first item is different from the second, and the second from the third, and so on. An operation is any action that transforms one series into another, or that produces a result from one or more series.
The most common series operations are:
- Insertion – placing a new item at a specific position (beginning, end, or somewhere in the middle)
- Deletion – removing an item from a specific position
- Reordering – changing the sequence according to some rule (alphabetical, chronological, by size, etc.)
- Comparison – checking whether two series are identical in both items and order
- Concatenation – joining two series end-to-end to form a longer series
- Slicing – extracting a contiguous portion of a series (for example, taking items 3 through 7)
The key idea is that order is meaningful. A series of dates is not the same if you swap two dates around. A list of names in alphabetical order is different from the same names in reverse alphabetical order. The operation you choose depends on what you want to preserve or change about that order.
Why Series Operations Matter
In commerce and humanities, you rarely work with raw numbers or formulas. Instead, you work with ordered collections of information: a timeline of historical events, a list of customers ranked by purchase date, a sequence of steps in a legal procedure, a catalogue of artworks arranged by period.
Series operations let you:
- Organise information so it becomes usable. A jumbled list of transactions is useless; sorting them by date turns them into a clear financial record.
- Update information as new data arrives. When a new customer registers, you insert their name at the correct alphabetical position. When a product is discontinued, you delete it from the catalogue.
- Compare information across sources. You might check whether two witness statements list events in the same order, or whether a shipment's packing list matches the order form item by item.
- Extract relevant portions. From a long chronology of a war, you might slice out only the events of a single year for analysis. …
Part (a)
Fill the blanks: numpy, array, Series, index.
import pandas as pd
import numpy as np
arr = np.array(['a', 'b', 'c'])
s = pd.Series(arr, index=['first', 'second', 'third'])
print(s)
Expected output:
first a
second b
third c
dtype: object …
Part (a): the blanks are numpy, array, Series, index; the Series prints a,b,c against first/second/third with dtype object.
Part (b): Series addition aligns on index labels — b=6.0, c=8.0, and the unmatched a,d become NaN (float64).
Part (a)
The code builds a NumPy array and wraps it in a labelled Pandas Series, so the four blanks are:
numpy— the module imported asnp.array—np.array(...)creates the array from the list.Series—pd.Series(...)builds the Series.index— the parameter that supplies the custom labels.
import pandas as pd
import numpy as np
arr = np.array(['a', 'b', 'c'])
s = pd.Series(arr, index=['first', 'second', 'third'])
print(s)
Expected output:
first a
second b
third c
dtype: object
``` …
- CBSE 2026Set 90/1/11 markMCQQ.In Pandas, when extracting a portion of a Series ser1 using ser1[start:end] with positional indices start and end, which of the following statements is true ? (A) The element at the end index is included in the output. (B) The element at the end index is excluded from the output. (C) The elements at both the start and end indices are excluded from the output. (D) The element at the start index is excluded from the output.
›Reveal solutionSolution
Pandas Series slicing with positional indices follows Python's standard slicing convention:
ser1[start:end]includes the element atstartbut excludes the element atend. The answer is (B).Why Pandas slicing works this way
Pandas inherits Python's fundamental slicing behavior for positional (integer-location) indexing. When you write
ser1[start:end], you're using implicit positional indexing (iloc-style), which follows the half-open interval convention: fromstartup to but not includingend, written as[start, end).This design choice is deliberate and consistent across Python sequences (lists, tuples, strings). The half-open interval makes slice arithmetic clean: the length of
ser1[start:end]is alwaysend - start, and consecutive slices likeser1[0:3]andser1[3:6]partition the data without overlap or gaps.Step-by-step verification
-
Create a simple Series to test
Consider a Series with five elements at positions 0, 1, 2, 3, 4:
import pandas as pd ser1 = pd.Series(['A', 'B', 'C', 'D', 'E'])The positional indices are 0 through 4.
-
Extract a slice using positional indices
If we write
ser1[1:4], we're asking for elements starting at position 1 up to (but not including) position 4:result = ser1[1:4] # Output: 1 B # 2 C # 3 DPosition 1 ('B') is included, position 4 ('E') is excluded.
-
Check the boundary behavior
- The element at
start = 1appears in the output. - The element at
end = 4does not appear in the output. - This confirms the half-open interval
[1, 4)— positions 1, 2 and 3 only.
- The element at
-
Evaluate each option …
-
- CBSE 2025Set 90/1/11 markMCQQ.What is the default index type for a Pandas Series if not explicitly specified? (A) String (B) List (C) Numeric (D) Boolean
›Reveal solutionSolution
If you don't specify an index when creating a Pandas Series, Pandas automatically assigns a numeric index starting from 0. The correct option is (C).
The key idea here is that Pandas is designed to work like a labelled array. When you don't provide labels, it falls back to the simplest, most universal labelling system: integers. This is exactly what NumPy arrays do by default — Pandas just carries that convention forward.
Let's see why this happens and why the other options don't fit.
-
What happens when you create a Series without an index?
When you write something like
pd.Series([10, 20, 30]), you haven't passed anindexparameter. Pandas sees this and says: "No labels given? I'll make my own." It generates aRangeIndexfrom 0 ton-1, wherenis the number of elements. So for three elements, the index becomes[0, 1, 2]. -
Why numeric and not string, list, or boolean?
- String (A): Strings are possible if you explicitly pass
index=['a','b','c'], but they are not the default. Pandas doesn't guess string labels — that would be arbitrary and unpredictable. - List (B): A list is a Python data structure, not a data type for an index. The index itself can be a list object, but the type of the index entries is what matters. The default entries are integers, not lists.
- Boolean (D): Booleans (
True,False) could technically be used as index labels, but they are not the default. If Pandas used booleans, you'd only ever have two possible labels — that would be useless for more than two elements.
- String (A): Strings are possible if you explicitly pass
-
What is the actual default type?
The default index is a
RangeIndex, which is a special kind of integer index. It behaves like a sequence of integers starting at 0, stepping by 1. So the type of each label isint(numeric). This is why option (C) is correct. …
-
- CBSE 2024Set 90/1/11 markMCQQ.What will be the output of the following Python code ? import pandas as pd dd={'One':1,'Two':2,'Three':3,'Seven':7} rr=pd.Series(dd) rr['Four']=4 print(rr) (A) One 1 Two 2 Three 3 Seven 7 dtype: int64 (B) One 1 Two 2 Three 3 Four 4 Seven 7 dtype: int64 (C) Four 4 One 1 Two 2 Three 3 Seven 7 dtype: int64 (D) One 1 Two 2 Three 3 Seven 7 Four 4 dtype: int64
›Reveal solutionSolution
A Pandas Series created from a dictionary preserves the dictionary's insertion order, and new elements added to the Series are appended to its end. The output will be (D).
A Pandas Series is a fundamental data structure in the Pandas library, representing a one-dimensional labeled array capable of holding any data type. Think of it like a column in a spreadsheet or a single column of data in a database table. Each item in a Series has a value and an associated label, called its index.
When you create a Pandas Series from a Python dictionary, a direct mapping occurs: the dictionary's keys become the Series' index labels, and the dictionary's values become the Series' data. A crucial point here, especially in modern Python (version 3.7 and later, which is standard for competitive programming and most environments), is that dictionaries maintain insertion order. This means the order in which you define key-value pairs in a dictionary is the order they will be stored and retrieved.
When you add a new element to an existing Series using an assignment like
series_name[new_index] = new_value, this new key-value pair is always appended to the end of the Series. It does not attempt to insert itself alphabetically or based on any other sorting logic unless you explicitly sort the Series afterwards.Let's trace the code step by step.
-
Importing Pandas:
import pandas as pdThis line imports the Pandas library and assigns it the conventional alias
pd. This allows us to use Pandas functions and classes by prefixing them withpd.. -
Creating a Dictionary:
dd={'One':1,'Two':2,'Three':3,'Seven':7}Here, a standard Python dictionary named
ddis created. It contains four key-value pairs. Due to Python's dictionary behavior (since version 3.7), the order of these elements is preserved as: 'One', 'Two', 'Three', 'Seven'. -
Creating a Pandas Series from the Dictionary:
rr=pd.Series(dd)This line converts the dictionary
ddinto a Pandas Series namedrr. The keys ofdd('One', 'Two', 'Three', 'Seven') become the index ofrr, and their corresponding values (1, 2, 3, 7) become the data. Since dictionaries preserve insertion order, the Seriesrrwill initially look like this:One 1 Two 2 Three 3 Seven 7 dtype: int64ImportantPython dictionaries (from version 3.7 onwards) preserve the order of insertion. When a Pandas Series is created from such a dictionary, it respects this order.
-
Adding a New Element to the Series:
rr['Four']=4 ``` …
-
- CBSE 2024Set 90/1/11 markMCQQ.Which of the following command will not show first five rows from the Pandas series named S1 ? (A) S1[0:5] (B) S1.head() (C) S1.head(5) (D) S1.head[0:5]
›Reveal solutionSolution
Option (D)
S1.head[0:5]is the only command that will not show the first five rows, because it uses square brackets instead of parentheses — a syntax error in Pandas.Let’s think about what each of these commands actually does. In Pandas, a Series is like a labelled one-dimensional array. When you want to peek at the beginning of a Series, you have two standard ways: slicing with square brackets, or using the
.head()method.Option (A)
S1[0:5]uses standard Python slicing. This works perfectly — it returns the elements at index positions 0, 1, 2, 3, and 4, which are the first five rows. Slicing in Pandas follows the same rules as Python lists: start inclusive, end exclusive.Option (B)
S1.head()calls the.head()method with no argument. By default,.head()returns the first five rows. So this is correct and will show exactly what we want.Option (C)
S1.head(5)is the explicit version of the same method — you’re telling Pandas “give me the first 5 rows.” This works identically toS1.head().Now look at option (D)
S1.head[0:5]. This is the odd one out. The.head()is a method, which means it must be called with parentheses — like.head()or.head(5). Using square brackets after.headtries to treat it as if it were a list or a dictionary, not a method. Python will raise aTypeErrorsaying that the object is not subscriptable. This command will not execute at all, let alone show the first five rows. … - CBSE 2023Set 90/1/11 markMCQQ.What will be the output of the following code? import pandas as pd myser = pd.Series([0, 0, 0]) print(myser) (A) 0 0 0 0 0 0 (B) 0 1 0 1 0 2 (C) 0 0 1 0 2 0 (D) 0 0 1 1 2 2
›Reveal solutionSolution
pd.Series([0, 0, 0])prints each element asindex valueon its own line, giving0 0,1 0,2 0— reading straight across, that's0 0 1 0 2 0, option (C).Trace
import pandas as pd myser = pd.Series([0, 0, 0]) print(myser)pd.Series([0, 0, 0])builds a 1-D labelled array from the list[0, 0, 0].- Since no index is supplied, pandas assigns the default RangeIndex:
0, 1, 2. - Each element keeps the value
0from the input list.
So the Series looks like:
index value 0 0 1 0 2 0 Actual output
0 0 1 0 2 0 dtype: int64 ``` …
🎓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.