當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python dask.dataframe.DataFrame.select_dtypes用法及代碼示例

用法:

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
  • 如果includeexclude都為空
  • 如果 includeexclude 有重疊的元素
  • 如果傳入任何類型的字符串 dtype。

注意

  • 全選數字類型,使用np.number或者'number'
  • 要選擇字符串,您必須使用objectdtype,但請注意,這將返回全部對象 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

相關用法


注:本文由純淨天空篩選整理自dask.org大神的英文原創作品 dask.dataframe.DataFrame.select_dtypes。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。