3.2. Series Attributes

3.2.1. SetUp

>>> import pandas as pd
>>>
>>> data = pd.Series(['a', 'b', 'c'])

3.2.2. Size

>>> data.size
3

3.2.3. NDim

  • Number of Dimensions

>>> data.ndim
1

3.2.4. Shape

>>> data.shape
(3,)

3.2.5. Index

  • More information in Pandas Series Index

>>> data
0    a
1    b
2    c
dtype: object
>>> data.index
RangeIndex(start=0, stop=3, step=1)

3.2.6. Values

>>> data.values
array(['a', 'b', 'c'], dtype=object)

3.2.7. Assignments

Code 3.47. 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

    >>> assert result is not Ellipsis, \
    'Assign result to variable: `result`'
    >>> assert all(type(x) is not Ellipsis for x in result.values()), \
    'Assign result to dict values in `result`'
    >>> assert type(result) is dict, \
    'Variable `result` has invalid type, should be `dict`'

    >>> 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'])

# type: dict[str, int|dtype|tuple]
result = {
    'number of dimensions': ...,
    'number of elements': ...,
    'data type': ...,
    'shape': ...,
}