maxframe.dataframe.DataFrame.select_dtypes#

DataFrame.select_dtypes(include=None, exclude=None)#

根据列的数据类型返回 DataFrame 列的一个子集。

参数:
  • include (scalar or list-like) -- 要包含/排除的数据类型或字符串的选择。至少需要提供其中一个参数。

  • exclude (scalar or list-like) -- 要包含/排除的数据类型或字符串的选择。至少需要提供其中一个参数。

返回:

包含 include 中的数据类型并排除 exclude 中的数据类型的帧的子集。

返回类型:

DataFrame

抛出:

ValueError --

  • If both of include and exclude are empty * If include and exclude have overlapping elements * If any kind of string dtype is passed in.

参见

DataFrame.dtypes

返回每个列数据类型的 Series。

备注

  • 要选择所有 数值 类型,请使用 np.number'number'

  • 要选择字符串,您必须使用 object 数据类型,但请注意这将返回 所有 对象数据类型列

  • 参见 numpy 数据类型层次结构

  • 要选择日期时间,请使用 np.datetime64'datetime''datetime64'

  • 要选择时间差,请使用 np.timedelta64'timedelta''timedelta64'

  • 要选择 Pandas 分类数据类型,请使用 'category'

  • 要选择 Pandas 带时区的日期时间数据类型,请使用 'datetimetz'``(0.20.0 新增)或 ``'datetime64[ns, tz]'

示例

>>> import maxframe.dataframe as md
>>> df = md.DataFrame({'a': [1, 2] * 3,
...                    'b': [True, False] * 3,
...                    'c': [1.0, 2.0] * 3})
>>> df.execute()
        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').execute()
   b
0  True
1  False
2  True
3  False
4  True
5  False
>>> df.select_dtypes(include=['float64']).execute()
   c
0  1.0
1  2.0
2  1.0
3  2.0
4  1.0
5  2.0
>>> df.select_dtypes(exclude=['int64']).execute()
       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