pandas.api.types.is_scalar

pandas.api.types.is_scalar()

Return True if given value 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, False otherwise

Examples

>>> dt = pd.datetime.datetime(2018, 10, 3)
>>> pd.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
Scroll To Top