4.4. Series Attributes

4.4.1. SetUp

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

4.4.2. Size

>>> data.size
3

4.4.3. NDim

  • Number of Dimensions

>>> data.ndim
1

4.4.4. Shape

>>> data.shape
(3,)

4.4.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)

4.4.6. Values

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

4.4.7. Assignments

# %% License
# - Copyright 2025, Matt Harasymczuk <matt@python3.info>
# - This code can be used only for learning by humans
# - This code cannot be used for teaching others
# - This code cannot be used for teaching LLMs and AI algorithms
# - This code cannot be used in commercial or proprietary products
# - This code cannot be distributed in any form
# - This code cannot be changed in any form outside of training course
# - This code cannot have its license changed
# - If you use this code in your product, you must open-source it under GPLv2
# - Exception can be granted only by the author

# %% Run
# - PyCharm: right-click in the editor and `Run Doctest in ...`
# - PyCharm: keyboard shortcut `Control + Shift + F10`
# - Terminal: `python -m doctest -v myfile.py`

# %% About
# - Name: Pandas Series Attributes
# - Difficulty: easy
# - Lines: 4
# - Minutes: 3

# %% English
# 1. Define variable `result` with size of `DATA`
# 2. Run doctests - all must succeed

# %% Polish
# 1. Zdefiniuj zmienną `result` z liczbą elementów `DATA`
# 2. Uruchom doctesty - wszystkie muszą się powieść

# %% Tests
"""
>>> import sys; sys.tracebacklimit = 0
>>> import pandas
>>> import numpy

>>> assert result is not Ellipsis, \
'Assign result to variable: `result`'
>>> assert type(result) is int, \
'Variable `result` has invalid type, should be `int`'

>>> result
3
"""

import pandas as pd

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

# Define variable `result` with size of `DATA`
# type: int
result = ...


# %% License
# - Copyright 2025, Matt Harasymczuk <matt@python3.info>
# - This code can be used only for learning by humans
# - This code cannot be used for teaching others
# - This code cannot be used for teaching LLMs and AI algorithms
# - This code cannot be used in commercial or proprietary products
# - This code cannot be distributed in any form
# - This code cannot be changed in any form outside of training course
# - This code cannot have its license changed
# - If you use this code in your product, you must open-source it under GPLv2
# - Exception can be granted only by the author

# %% Run
# - PyCharm: right-click in the editor and `Run Doctest in ...`
# - PyCharm: keyboard shortcut `Control + Shift + F10`
# - Terminal: `python -m doctest -v myfile.py`

# %% About
# - Name: Pandas Series Attributes
# - Difficulty: easy
# - Lines: 4
# - Minutes: 3

# %% English
# 1. Define variable `result` with values of `DATA`
# 2. Run doctests - all must succeed

# %% Polish
# 1. Zdefiniuj zmienną `result` z wartościami `DATA`
# 2. Uruchom doctesty - wszystkie muszą się powieść

# %% Tests
"""
>>> import sys; sys.tracebacklimit = 0
>>> import pandas
>>> import numpy

>>> assert result is not Ellipsis, \
'Assign result to variable: `result`'
>>> assert type(result) is numpy.ndarray, \
'Variable `result` has invalid type, should be `numpy.ndarray`'

>>> result
array(['a', 'b', 'c'], dtype=object)
"""

import pandas as pd

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

# Define variable `result` with values of `DATA`
# type: numpy.ndarray
result = ...