pandas.api.types.is_scalar#

pandas.api.types.is_scalar(val)#

Return True if given object is scalar.

Parameters:
valobject

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.

See also

api.types.is_list_like

Check if the input is list-like.

api.types.is_integer

Check if the input is an integer.

api.types.is_float

Check if the input is a float.

api.types.is_bool

Check if the input is a boolean.

Examples

>>> import datetime
>>> 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