用法:
DataFrame.select_dtypes(include=None, exclude=None)
根據列 dtypes 返回 DataFrame 列的子集。
此文檔字符串是從 pandas.core.frame.DataFrame.select_dtypes 複製而來的。
可能存在與 Dask 版本的一些不一致之處。
- include, exclude:標量或list-like
要包含/排除的數據類型或字符串的選擇。必須至少提供這些參數之一。
- DataFrame
幀的子集,包括
include
中的 dtype,不包括exclude
中的 dtype。
- ValueError
- 如果
include
和exclude
都為空 - 如果
include
和exclude
有重疊的元素 - 如果傳入任何類型的字符串 dtype。
- 如果
參數:
返回:
拋出:
注意:
- 全選數字類型,使用
np.number
或者'number'
- 要選擇字符串,您必須使用
object
dtype,但請注意,這將返回全部對象 dtype 列 - 見numpy dtype hierarchy
- 要選擇日期時間,請使用
np.datetime64
,'datetime'
或'datetime64'
- 要選擇時間增量,請使用
np.timedelta64
,'timedelta'
或'timedelta64'
- 要選擇 Pandas 分類數據類型,請使用
'category'
- 要選擇 Pandas datetimetz dtypes,請使用
'datetimetz'
(0.20.0 中的新函數)或'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=['int64']) 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
相關用法
- Python dask.dataframe.DataFrame.set_index用法及代碼示例
- Python dask.dataframe.DataFrame.sub用法及代碼示例
- Python dask.dataframe.DataFrame.std用法及代碼示例
- Python dask.dataframe.DataFrame.shape用法及代碼示例
- Python dask.dataframe.DataFrame.sum用法及代碼示例
- Python dask.dataframe.DataFrame.shuffle用法及代碼示例
- Python dask.dataframe.DataFrame.squeeze用法及代碼示例
- Python dask.dataframe.DataFrame.sort_values用法及代碼示例
- Python dask.dataframe.DataFrame.applymap用法及代碼示例
- Python dask.dataframe.DataFrame.mod用法及代碼示例
- Python dask.dataframe.DataFrame.cummin用法及代碼示例
- Python dask.dataframe.DataFrame.truediv用法及代碼示例
- Python dask.dataframe.DataFrame.round用法及代碼示例
- Python dask.dataframe.DataFrame.ne用法及代碼示例
- Python dask.dataframe.DataFrame.partitions用法及代碼示例
- Python dask.dataframe.DataFrame.to_bag用法及代碼示例
- Python dask.dataframe.DataFrame.any用法及代碼示例
- Python dask.dataframe.DataFrame.itertuples用法及代碼示例
- Python dask.dataframe.DataFrame.count用法及代碼示例
注:本文由純淨天空篩選整理自dask.org大神的英文原創作品 dask.dataframe.DataFrame.select_dtypes。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。