pandas.api.types.is_string_dtype#

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

检查提供的数组或 dtype 是否为字符串 dtype。

如果传递了对象 dtype 的数组,则元素必须推断为字符串。

Parameters:
arr_or_dtypearray-like or dtype

要检查的数组或 dtype。

Returns:
boolean

数组或 dtype 是否为字符串 dtype。

Examples

>>> from pandas.api.types import is_string_dtype
>>> is_string_dtype(str)
True
>>> is_string_dtype(object)
True
>>> is_string_dtype(int)
False
>>> is_string_dtype(np.array(['a', 'b']))
True
>>> is_string_dtype(pd.Series([1, 2]))
False
>>> is_string_dtype(pd.Series([1, 2], dtype=object))
False