Informatics Practices
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 Object | ndarrays |
|---|---|
| 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. |
Related Questions
What is the significance of Pandas library ?
Name some common data structures of Python's Pandas library.
Write single line Pandas statement for the following. (Assuming necessary modules have been imported) :
Declare a Pandas series named Packets having dataset as :
[125, 92, 104, 92, 85, 116, 87, 90]
Write commands to print following details of a Series object seal :
(a) if the series is empty
(b) indexes of the series
(c) The data type of underlying data
(d) if the series stores any NaN values