Movatterモバイル変換


[0]ホーム

URL:


Skip to main content
Ctrl+K

pandas.DataFrame.select_dtypes#

DataFrame.select_dtypes(include=None,exclude=None)[source]#

Return a subset of the DataFrame’s columns based on the column dtypes.

Parameters:
include, excludescalar or list-like

A selection of dtypes or strings to be included/excluded. At leastone of these parameters must be supplied.

Returns:
DataFrame

The subset of the frame including the dtypes ininclude andexcluding the dtypes inexclude.

Raises:
ValueError
  • If both ofinclude andexclude are empty

  • Ifinclude andexclude have overlapping elements

  • If any kind of string dtype is passed in.

See also

DataFrame.dtypes

Return Series with the data type of each column.

Notes

  • To select allnumeric types, usenp.number or'number'

  • To select strings you must use theobject dtype, but note thatthis will returnall object dtype columns. Withpd.options.future.infer_string enabled, using"str" willwork to select all string columns.

  • See thenumpy dtype hierarchy

  • To select datetimes, usenp.datetime64,'datetime' or'datetime64'

  • To select timedeltas, usenp.timedelta64,'timedelta' or'timedelta64'

  • To select Pandas categorical dtypes, use'category'

  • To select Pandas datetimetz dtypes, use'datetimetz'or'datetime64[ns,tz]'

Examples

>>>df=pd.DataFrame({'a':[1,2]*3,...'b':[True,False]*3,...'c':[1.0,2.0]*3})>>>df        a      b  c0       1   True  1.01       2  False  2.02       1   True  1.03       2  False  2.04       1   True  1.05       2  False  2.0
>>>df.select_dtypes(include='bool')   b0  True1  False2  True3  False4  True5  False
>>>df.select_dtypes(include=['float64'])   c0  1.01  2.02  1.03  2.04  1.05  2.0
>>>df.select_dtypes(exclude=['int64'])       b    c0   True  1.01  False  2.02   True  1.03  False  2.04   True  1.05  False  2.0

[8]ページ先頭

©2009-2025 Movatter.jp