只获取python blaze对象中的数字列



我有一个类似的blaze数据对象

import blaze as bz
bdata = bz.Data([(1, 'Alice', 100.9),
           (2, 'Bob', 200.6),
           (3, 'Charlie', 300.45),
           (5, 'Edith', 400)],
          fields=['id', 'name', 'amount'])
bdata
  | id | name   | amount
--------------------------
0 | 1  | Alice  | 100.90
1 | 2  | Bob    | 200.60
2 | 3  | Charlie| 300.45
3 | 5  | Edith  | 400.00

我只想得到那些有numeric datatypes的列名。例如,这里只有idamount有数值。

我可以使用dshape获得列类型,如下所示

bdata.dshape
dshape("4 * {id: int64, name: string, amount: float64}")

但不确定如何正确利用这一点。我知道如何使用_get_numeric_data()函数在pandas中做同样的事情。在blaze 中查找类似的函数或代码

还有一种更简单的方法。以下是实现的一种方法

In [75]:
def get_numeric_cols(dshape):
    shape = dshape.parameters[-1].dict
    cols = []
    for k in shape:
        type = str(shape[k])
        if type.startswith("int") or type.startswith("float"):
            cols.append(k)
    return cols
In [76]: get_numeric_cols(bdata.dshape)
Out[76]: ['amount', 'id']

基本上,查找int*float*类型?

最新更新