selection from a DataFrame
removal from a DataFrame
selection and removal from a DataFrame
select(f, DF, key, b1, ..., bn)
select[inplace](f, DF, key, b1, ..., bn)
remove(f, DF, key, b1, ..., bn)
remove[inplace](f, DF, key, b1, ..., bn)
selectremove(f, DF, key, b1, ..., bn)
selectremove[inplace](f, DF, key, b1, ..., bn)
a DataFrame object
specifies the key column of DF
b1, ..., bn
(optional) extra arguments for f
When called on a DataFrame object, the select command returns a DataFrame object consisting of those rows where the key column entry satisfies the given criterion.
When called on a DataFrame object, the remove command returns a DataFrame object consisting of those rows where the key column entry does not satisfy the given criterion.
When called on a DataFrame object, the selectremove command returns a sequence of two DataFrame objects, the first consisting of those rows where the key column entry satisfies the given criterion, and the second consisting of the other rows.
The commands can also be called on other types of arguments. This behavior is described on the main help page for select.
The criterion used for deciding whether a row of the DataFrame is included in the result is to call f⁡x,b1,...,bn, where x is the entry in that row and in the key column. This should return true or false (or FAIL, which is interpreted in the same way as false). If you call select, then the returned DataFrame will contain this row if and only if the value returned is true. If you call remove, then the returned DataFrame will contain this row if and only if the value returned is false (or FAIL).
The value key can be a positive or negative integer to indicate the position of the key column, or the label of the key column. This is interpreted in the same way as for indexing a DataFrame, so the first test is if key is a valid column position, and if not, the second test is whether it is a valid column label. You cannot specify a range, list, rtable, or Boolean DataSeries or DataFrame.
Any row that is included in the result will have the same label that it has in DF. All columns have the same labels as in DF.
If you call select[inplace] or remove[inplace], the command will modify the DataFrame object DF and return it. The calling sequences with no index on the command name will return a new DataFrame object and leave DF unchanged. If you call selectremove[inplace], then the command will modify DF to be the first DataFrame returned, and the second DataFrame will be a new DataFrame object.
You can do similar things with DataFrame indexing using a Boolean DataSeries. See the example below. Indexing also allows for criteria involving multiple columns, which is not supported with the select, remove, and selectremove commands.
We split df, below, into rows with prime and non-prime entries in various ways, using the isprime command as the testing criterion.
df ≔ DataFrame⁡Matrix⁡4,5,i,j→2⁢i−j,rows=a,b,c,d,columns=A,B,C,D,E
The rows for which the first column is a prime.
We can get the same result if we specify the first column with its label, A.
A third way to get the same result is by indexing with a Boolean DataSeries.
We can obtain the rows where the entries in column D are non-prime using remove.
If we want to obtain both the rows where the entries are prime, and where they are nonprime, we can use selectremove. Below, we show this for column C.
If we want to select the entries of a particular type, then we can use the optional fourth argument to select.
The original DataFrame, df, is unchanged, because we used the commands without the inplace index.
If we call select with the inplace index, then df is modified in-place.
The DataFrame/select, DataFrame/remove and DataFrame/selectremove commands were introduced in Maple 2019.
For more information on Maple 2019 changes, see Updates in Maple 2019.
main help page for select
Download Help Document
What kind of issue would you like to report? (Optional)