I am unable to perform a standard in
operation with a pre-defined list of items. I am looking to do something like this:
# Construct a simple example frame
from datatable import *
df = Frame(V1=['A','B','C','D'], V2=[1,2,3,4])
# Filter frame to a list of items (THIS DOES NOT WORK)
items = ['A','B']
df[f.V1 in items,:]
This example results in the error:
TypeError: A boolean value cannot be used as a row selector
Unfortunately, there doesn't appear to be a built-in object for in
operations. I would like to use something like the %in%
operator that is native to the R language. Is there any method for accomplishing this in python?
I can take this approach with the use of multiple 'equals' operators, but this is inconvenient when you want to consider a large number of items:
df[(f.V1 == 'A') | (f.V1 == 'B'),:]
datatable 0.10.1
python 3.6
Series.isin
for this, but it doesn't look likedatatable
has anything similar. (Thedatatable
documentation seems really sparse.) – Farverin
that broadcasts over the LHS, which Python'sin
can't do. – Farver