I need a way to remove a column from a dataset by column index or name. I’ve been toying with a loop through the dataset based on a list of the headers for the columns I want to keep, but coming up short. Any help would be greatly appreciated.
Thanks!
There an expression function and a scripting function that do this for you.
@pturmel: Not fair - I got called into a meeting.
Can’t believe I missed that scripting function. Thanks for your help!
Heh. I'm having a rare quiet afternoon--more time for the forum. (:
{ The calm before next week's scheduled storm. }
I just had this issue too, and filterColumn
certainly isn't the obvious solution. Filtering a dataset is a different action to explicitly removing columns. It would still be good to have a "removeColumns" function to remove certain columns instead of having to do the invert of this.
I wrote a function to do it for me:
def removeColumns(ds, colsRemove):
""" Removes columns from a dataset. colsRemove should be a list of column names to remove. """
colsKeep = ds.columnNames
for col in colsRemove: colsKeep.remove(col)
ds = system.dataset.filterColumns(ds, colsKeep)
return ds
On another note, @Paul.Scott it would be good it the doco pointed out that this function (filterColumns) can also be used to inadvertently re-arrange columns in a dataset as well, as columns will appear in the order in which you define in the filter columns list.