2

I have a datatable frame with about 30 columns, here I wanted to look at only 26 cols by keeping the remaining 4 columns a side in Frame,

would the unary operator be useful to deselect the columns as follows

DT[:,-(f.x)]

I have tried it but it's inserting the operator to the column values, could you please let me know how to do it in pydatatable way?.

Pasha
  • 6,298
  • 2
  • 22
  • 34
myamulla_ciencia
  • 1,282
  • 1
  • 8
  • 30

1 Answers1

1

The operator .remove() can be used to remove columns from an existing column selection. If you need to select all columns except for a few, then first select all columns using f[:], then remove those you don't like. Thus:

>>> from datatable import f, dt
>>> DT = dt.Frame(names=list('ABCDEFGHIJ'))

>>> DT[:, f[:].remove(f.E)]
   |  A   B   C   D   F   G   H   I   J
-- + --  --  --  --  --  --  --  --  --

[0 rows x 9 columns]

>>> DT[:, f[:].remove([f.B, f.G, f.J])]
   |  A   C   D   E   F   H   I
-- + --  --  --  --  --  --  --

[0 rows x 7 columns]

See https://datatable.readthedocs.io/en/latest/f-expressions.html#modifying-a-columnset for more details

Pasha
  • 6,298
  • 2
  • 22
  • 34
  • Pasha, i have another question: here i have framed a custom function to deselect the passed fields as showed in this code, def pydt_select_mult_cols(DT,*cols): list_of_cols = [*cols] return DT[:,f[:].remove([list_of_cols])].. this is not working, would you like to give any input ?. – myamulla_ciencia May 21 '20 at 04:52
  • here is a function to select the required fields from DT.. def pydt_select_mult_cols(DT,*cols): list_of_cols = [*cols] return DT[:,list_of_cols], It's working in this case. – myamulla_ciencia May 21 '20 at 04:54
  • Could you please write yours comments for this case? – myamulla_ciencia May 21 '20 at 17:35