DataFrame.select_dtypes(self, include=None, exclude=None)
[source]
Return a subset of the DataFrame’s columns based on the column dtypes.
Parameters: |
|
---|---|
Returns: |
|
Raises: |
|
np.number
or 'number'
object
dtype, but note that this will return all object dtype columnsnp.datetime64
, 'datetime'
or 'datetime64'
np.timedelta64
, 'timedelta'
or 'timedelta64'
'category'
'datetimetz'
(new in 0.20.0) or 'datetime64[ns, tz]'
>>> df = pd.DataFrame({'a': [1, 2] * 3, ... 'b': [True, False] * 3, ... 'c': [1.0, 2.0] * 3}) >>> df a b c 0 1 True 1.0 1 2 False 2.0 2 1 True 1.0 3 2 False 2.0 4 1 True 1.0 5 2 False 2.0
>>> df.select_dtypes(include='bool') b 0 True 1 False 2 True 3 False 4 True 5 False
>>> df.select_dtypes(include=['float64']) c 0 1.0 1 2.0 2 1.0 3 2.0 4 1.0 5 2.0
>>> df.select_dtypes(exclude=['int']) b c 0 True 1.0 1 False 2.0 2 True 1.0 3 False 2.0 4 True 1.0 5 False 2.0
© 2008–2012, AQR Capital Management, LLC, Lambda Foundry, Inc. and PyData Development Team
Licensed under the 3-clause BSD License.
https://pandas.pydata.org/pandas-docs/version/0.25.0/reference/api/pandas.DataFrame.select_dtypes.html