pandas_select.column.HasDtype¶
-
class
HasDtype(include=None, exclude=None)[source]¶ Select columns based on the column dtypes.
- Parameters
include (scalar or list-like) – A selection of dtypes or strings to be included/excluded. At least one of these parameters must be supplied.
exclude (scalar or list-like) – A selection of dtypes or strings to be included/excluded. At least one of these parameters must be supplied.
- Raises
ValueError – If both of
includeandexcludeare empty; ifincludeandexcludehave overlapping elements; if any kind of string dtype is passed in.
Notes
To select all numeric types, use
numpy.number,'number'or :class:`AllNumeric.To select strings you must use the
object,stringdtype if pandas version > 1.0.0, or orAllStrSee the numpy dtype hierarchy
To select datetimes, use
numpy.datetime64,'datetime'or'datetime64'.To select timedeltas, use
numpy.timedelta64,'timedelta'or'timedelta64'.To select Pandas categorical dtypes, use
'category'orAllCat.To select Pandas datetimetz dtypes, use
'datetimetz'or'datetime64[ns, tz]'.
Examples
>>> df = pd.DataFrame({"a": [1, 2], ... "b": [True, False], ... "c": [1.0, 2.0]}) >>> df a b c 0 1 True 1.0 1 2 False 2.0 >>> df[HasDtype("int")] a 0 1 1 2 >>> import numpy as np >>> df[HasDtype(include=np.number, exclude=["int"])] c 0 1.0 1 2.0