pandas.api.types.infer_dtype#
- pandas.api.types.infer_dtype(value, skipna=True)#
返回标量或类列表值的类型标签。
- Parameters:
- valuescalar, list, ndarray, or pandas type
- <strong>skipna</strong>bool, default True
在推断类型时忽略 NaN 值。
- Returns:
- str
描述输入数据的通用类型。
- 结果可包括:
- string
- bytes
- floating
- integer
- mixed-integer
- mixed-integer-float
- decimal
- complex
- categorical
- boolean
- datetime64
- datetime
- date
- timedelta64
- timedelta
- time
- period
- mixed
- unknown-array
- Raises:
- TypeError
如果它是 ndarray-like 但无法推断 dtype
Notes
‘mixed’ 是其他任何无法专门化的通用类别
‘mixed-integer-float’ 是浮点数和整数
‘mixed-integer’ 是整数与非整数混合
‘unknown-array’ 是任何具有 dtype 属性但 pandas 未知的 dtype(例如,外部扩展数组)的通用类别
Examples
>>> from pandas.api.types import infer_dtype >>> infer_dtype(['foo', 'bar']) 'string'
>>> infer_dtype(['a', np.nan, 'b'], skipna=True) 'string'
>>> infer_dtype(['a', np.nan, 'b'], skipna=False) 'mixed'
>>> infer_dtype([b'foo', b'bar']) 'bytes'
>>> infer_dtype([1, 2, 3]) 'integer'
>>> infer_dtype([1, 2, 3.5]) 'mixed-integer-float'
>>> infer_dtype([1.0, 2.0, 3.5]) 'floating'
>>> infer_dtype(['a', 1]) 'mixed-integer'
>>> from decimal import Decimal >>> infer_dtype([Decimal(1), Decimal(2.0)]) 'decimal'
>>> infer_dtype([True, False]) 'boolean'
>>> infer_dtype([True, False, np.nan]) 'boolean'
>>> infer_dtype([pd.Timestamp('20130101')]) 'datetime'
>>> import datetime >>> infer_dtype([datetime.date(2013, 1, 1)]) 'date'
>>> infer_dtype([np.datetime64('2013-01-01')]) 'datetime64'
>>> infer_dtype([datetime.timedelta(0, 1, 1)]) 'timedelta'
>>> infer_dtype(pd.Series(list('aabc')).astype('category')) 'categorical'