CBSE Class 12 Informatics Practices Question 92 of 167

Python Pandas — I — Question 3

Back to all questions
3
Question

Question 3

How is a Series object different from and similar to ndarrays ? Support your answer with examples.

Answer

A Series object in Pandas is both similar to and different from ndarrays (NumPy arrays).

Similarities:

Both Series and ndarrays store homogeneous data, meaning all elements must be of the same data type (e.g., integers, floats, strings).

Differences:

Series Objectndarrays
It supports explicit indexing, i.e., we can programmatically choose, provide and change indexes in terms of numbers or labels.It does not support explicit indexing, only supports implicit indexing whereby the indexes are implicitly given 0 onwards.
It supports indexes of numeric as well of string types.It supports indexes of only numeric types.
It can perform vectorized operations on two series objects, even if their shapes are different by using NaN for non-matching indexes/labels.It can perform vectorized operations on two ndarrays only if their shapes match.
It takes more memory compared to a numpy array.It takes lesser memory compared to a Series object.