pandas.api.types.is_bool_dtype#

pandas.api.types.is_bool_dtype(arr_or_dtype)[源代码]#

检查提供的数组或 dtype 是否为布尔 dtype。

Parameters:
arr_or_dtypearray-like or dtype

要检查的数组或 dtype。

Returns:
boolean

数组或 dtype 是否为布尔 dtype。

Notes

_is_boolean 属性设置为 True 时,ExtensionArray 被认为是布尔型的。

Examples

>>> from pandas.api.types import is_bool_dtype
>>> is_bool_dtype(str)
False
>>> is_bool_dtype(int)
False
>>> is_bool_dtype(bool)
True
>>> is_bool_dtype(np.bool_)
True
>>> is_bool_dtype(np.array(['a', 'b']))
False
>>> is_bool_dtype(pd.Series([1, 2]))
False
>>> is_bool_dtype(np.array([True, False]))
True
>>> is_bool_dtype(pd.Categorical([True, False]))
True
>>> is_bool_dtype(pd.arrays.SparseArray([True, False]))
True