pandas.api.types.
is_scalar
Return True if given object is scalar.
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.
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