Attributes are the properties of any object. Here we will discuss all the Series attributes with programming examples. All the important Series attributes according to the CBSE Class 12 Informatics practices syllabus are given below in the table:-
Attributes | Description |
---|---|
Series.index | Range of the index (axis labels) of the Series. |
Series.values | Return Series as ndarray or ndarray like depending upon dtype |
Series.dtype | Return the dtype object of the underlying data. |
Series.shape | Return a tuple of the shape of the underlying data. |
Series.nbytes | Return the number of bytes in the underlying data. |
Series.ndim | The number of dimensions of the underlying data, by definition 1. |
Series.size | Return the number of elements in the underlying data. |
Series.hasnans | Return if I have any nans; enables various perf speedups. |
Series.empty | Return true if Series is empty |
at, iat | To access a single value from Series |
loc, iloc | To access slices from Series |
1 2 3 4 5 6 7 8 9 10 11 12 | import pandas as pd student = pd.Series(["Sonal", "Rahul", "Mohan", "Siya",]) print(student) ''' Output: 0 Sonal 1 Rahul 2 Mohan 3 Siya dtype: object ''' |
1 2 | >>> student.index RangeIndex(start=0, stop=4, step=1) |
2. Series.values
1 2 | >>> student.values array(['Sonal', 'Rahul', 'Mohan', 'Siya'], dtype=object) |
1 2 | >>> student.dtype dtype('O') |
1 2 | >>> student.shape (4,) |
1 2 | >>> student.nbytes 32 |
1 2 | >>> student.ndim 1 |
1 2 | >>> student.size 4 |
1 2 | >>> student.hasnans False |
1 2 | >>> student.empty False |