Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

datatable filter by not in

Trying to subset a datatable by values that don't match a list:

DT1 = dt.Frame(A = ['a', 'b', 'c', 'd'])
sel_rows = functools.reduce(operator.or_,(f.A != obs for obs  in ['a', 'b']))
DT1[sel_rows, :]

However this returns all the rows,

I'd expect only the rows with only 'c' and 'd' in column A to returned.

Why is everything returned? How do I edit this to have that behavior.

like image 316
Rafael Avatar asked Jan 01 '26 07:01

Rafael


1 Answers

Solved it by changing operator.or to operator.and...

DT1 = dt.Frame(A = ['a', 'b', 'c', 'd'])
sel_rows = functools.reduce(operator.and_,(f.A != obs for obs in ['a', 'b']))
DT1[sel_rows, :]
like image 140
Rafael Avatar answered Jan 02 '26 19:01

Rafael



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!