0

类似于此示例py-datatable 'in' 运算符?但使用另一个数据表创建列表,在最后一步失败:

import datatable as dt
from datatable import f, by, count
import operator
import functools

DT1 = dt.Frame(A = range(5))
DT2 = dt.Frame(B = range(3, 10))
sel_obs = DT2['B'].to_list()
filter_rows = functools.reduce(operator.or_,(f.A==obs for obs in sel_obs))
DT1[filter_rows,:]

但是出现错误:

TypeError:i-expression 评估为 7 列

4

1 回答 1

1

微小的变化,它的工作原理,见第 3 行

DT1 = dt.Frame(A = range(5))
DT2 = dt.Frame(B = range(3, 10))
sel_obs = DT2['B'].to_list()[0] ## adding [0] as to_list returns nested list
filter_rows = functools.reduce(operator.or_,(f.A==obs for obs in sel_obs))

DT1[filter_rows,:]
于 2021-08-09T20:06:29.347 回答