pandas.api.types.infer_dtype

pandas.api.types.infer_dtype()

Efficiently infer the type of a passed val, or list-like array of values. Return a string describing the type.

Parameters
valuescalar, list, ndarray, or pandas type
skipnabool, default False

Ignore NaN values when inferring the type.

New in version 0.21.0.

Returns
string describing the common type of the input data.
Results can include:
  • string
  • unicode
  • bytes
  • floating
  • integer
  • mixed-integer
  • mixed-integer-float
  • decimal
  • complex
  • categorical
  • boolean
  • datetime64
  • datetime
  • date
  • timedelta64
  • timedelta
  • time
  • period
  • mixed
Raises
****TypeError if ndarray-like but cannot infer the dtype

Notes

  • ‘mixed’ is the catchall for anything that is not otherwise specialized

  • ‘mixed-integer-float’ are floats and integers

  • ‘mixed-integer’ are integers mixed with non-integers

Examples

>>> 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'
>>> infer_dtype([Decimal(1), Decimal(2.0)])
'decimal'
>>> infer_dtype([True, False])
'boolean'
>>> infer_dtype([True, False, np.nan])
'mixed'
>>> infer_dtype([pd.Timestamp('20130101')])
'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'
Scroll To Top