pandas.api.types.is_scalar

pandas.api.types.is_scalar()

Return True if given object is scalar.

Parameters
val:object

This includes:

  • numpy array scalar (e.g. np.int64)

  • Python builtin numerics

  • Python builtin byte arrays and strings

  • None

  • datetime.datetime

  • datetime.timedelta

  • Period

  • decimal.Decimal

  • Interval

  • DateOffset

  • Fraction

  • Number.

Returns
bool

Return True if given object is scalar.

Examples

>>> dt = datetime.datetime(2018, 10, 3)
>>> pd.api.types.is_scalar(dt)
True
>>> pd.api.types.is_scalar([2, 3])
False
>>> pd.api.types.is_scalar({0: 1, 2: 3})
False
>>> pd.api.types.is_scalar((0, 2))
False

pandas supports PEP 3141 numbers:

>>> from fractions import Fraction
>>> pd.api.types.is_scalar(Fraction(3, 5))
True

© 2008–2021, AQR Capital Management, LLC, Lambda Foundry, Inc. and PyData Development Team
Licensed under the 3-clause BSD License.
https://pandas.pydata.org/pandas-docs/version/1.3.4/reference/api/pandas.api.types.is_scalar.html