如何根据pydatatable中的数据类型select列?

How to select columns based on their data types in pydatatable?

我正在创建一个数据表,如下所示,

spotify_songs_dt = dt.fread('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2020/2020-01-21/spotify_songs.csv')

它的列类型是,

spotify_songs_dt.stypes

这里我想只取出DT的数字字段,请问如何用数据表的方式实现。在 pandas 数据框中,我们有一种函数 select_dtypes() 。

如果您有框架 DT,那么 select 特定类型列的最直接方法是在 DT[:,j] select 中使用类型本身或者:

DT[:, bool]          # all boolean columns
DT[:, int]           # all integer columns
DT[:, float]         # all floating columns
DT[:, str]           # string columns
DT[:, dt.int32]      # columns with stype int32
DT[:, dt.ltype.int]  # columns with ltype `int`, same as DT[:, int]

也可以向 select 提供类型列表:

DT[:, [int, float]]          # integer and floating columns
DT[:, [dt.int32, dt.int64]]  # int32 and int64 columns

有时删除不需要的类型的列而不是select删除您需要的列可能也很有用:

del DT[:, str]