3.2. Series Attributes

3.2.1. Size

import pandas as pd

s = pd.Series(['a', 'b', 'c'])

s.size
# 3

3.2.2. NDim

  • Number of Dimensions

import pandas as pd

s = pd.Series(['a', 'b', 'c'])

s.ndim
# 1

3.2.3. Shape

import pandas as pd

s = pd.Series(['a', 'b', 'c'])

s.shape
# (3,)

3.2.4. Index

  • More information in Pandas Series Index

import pandas as pd

s = pd.Series(['a', 'b', 'c'])

s
# 0    a
# 1    b
# 2    c
# dtype: object

s.index
# RangeIndex(start=0, stop=3, step=1)

3.2.5. Values

import pandas as pd

s = pd.Series(['a', 'b', 'c'])

s.values
# array(['a', 'b', 'c'], dtype=object)

3.2.6. Assignments

Code 3.35. Solution
"""
* Assignment: Pandas Series Attributes
* Complexity: easy
* Lines of code: 7 lines
* Time: 5 min

English:
    1. Define `result: dict` with:
        a. number of dimensions;
        b. number of elements;
        c. data type;
        e. shape.
    2. Run doctests - all must succeed

Polish:
    1. Zdefiniuj `result: dict` z:
        a. liczbę wymiarów,
        b. liczbę elementów,
        c. typ danych,
        e. kształt.
    2. Uruchom doctesty - wszystkie muszą się powieść

Tests:
    >>> import sys; sys.tracebacklimit = 0

    >>> type(result) is dict
    True
    >>> result  # doctest: +NORMALIZE_WHITESPACE
    {'number of dimensions': 1,
     'number of elements': 3,
     'data type': dtype('O'),
     'shape': (3,)}
"""

import pandas as pd

DATA = pd.Series(['a', 'b', 'c'])

result = {
    'number of dimensions': ...,
    'number of elements': ...,
    'data type': ...,
    'shape': ...,
}