Data Wrangling with Python Datatable - Select Columns by Data Type

Datatable docs

ltype

stypes

from datatable import dt, f

df = dt.Frame({'a': [1, 2, 1, 2, 1, 2],
               'b': [True, False, True, False, True, False],
               'c': [1.0, 2.0, 1.0, 2.0, 1.0, 2.0]})
df

   |     a      b        c
   | int32  bool8  float64
-- + -----  -----  -------
 0 |     1      1        1
 1 |     2      0        2
 2 |     1      1        1
 3 |     2      0        2
 4 |     1      1        1
 5 |     2      0        2
[6 rows x 3 columns]
  • Select the boolean column :
df[:, f[bool]]

   |     b
   | bool8
-- + -----
 0 |     1
 1 |     0
 2 |     1
 3 |     0
 4 |     1
 5 |     0
[6 rows x 1 column]
  • Select the float64 column :
df[:, f[dt.float64]]

   |       c
   | float64
-- + -------
 0 |       1
 1 |       2
 2 |       1
 3 |       2
 4 |       1
 5 |       2
[6 rows x 1 column]
  • Exclude the int32 column :
df[:, [dtype.name != "int32" for dtype in df.stypes]]

   |     b        c
   | bool8  float64
-- + -----  -------
 0 |     1        1
 1 |     0        2
 2 |     1        1
 3 |     0        2
 4 |     1        1
 5 |     0        2
[6 rows x 2 columns]