0

Similar to this example py-datatable 'in' operator? but using another datatable to create a list, fails on the last step:

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,:]

However getting error:

TypeError: i-expression evaluated into 7 columns

Rafael
  • 3,096
  • 1
  • 23
  • 61

1 Answers1

1

Tiny change, and it works, see 3rd line

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,:]
Rafael
  • 3,096
  • 1
  • 23
  • 61
  • 3
    At first, I thought the code in the answer was identical to the last 5 lines of the code in the question. Then I noticed the `[0]`. Perhaps a comment in the answer would help? – andrewJames Aug 09 '21 at 21:37