Select, Remove - Maple Help

DataFrame/select

selection from a DataFrame

DataFrame/remove

removal from a DataFrame

DataFrame/selectremove

selection and removal from a DataFrame

 Calling Sequence 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)

Parameters

 f - Boolean-valued procedure DF - a DataFrame object key - specifies the key column of DF b1, ..., bn - (optional) extra arguments for f

Description

 • 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\left(x,\mathrm{b1},\mathrm{...},\mathrm{bn}\right)$, 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.

Examples

We split $\mathrm{df}$, below, into rows with prime and non-prime entries in various ways, using the isprime command as the testing criterion.

 > $\mathrm{df}≔\mathrm{DataFrame}\left(\mathrm{Matrix}\left(4,5,\left(i,j\right)↦2\cdot i-j\right),\mathrm{rows}=\left[a,b,c,d\right],\mathrm{columns}=\left[A,B,C,\mathrm{D},E\right]\right)$
 ${\mathrm{df}}{≔}\left[\begin{array}{cccccc}{}& {A}& {B}& {C}& {\mathrm{D}}& {E}\\ {a}& {1}& {0}& {-1}& {-2}& {-3}\\ {b}& {3}& {2}& {1}& {0}& {-1}\\ {c}& {5}& {4}& {3}& {2}& {1}\\ {d}& {7}& {6}& {5}& {4}& {3}\end{array}\right]$ (1)

The rows for which the first column is a prime.

 > $\mathrm{select}\left(\mathrm{isprime},\mathrm{df},1\right)$
 $\left[\begin{array}{cccccc}{}& {A}& {B}& {C}& {\mathrm{D}}& {E}\\ {b}& {3}& {2}& {1}& {0}& {-1}\\ {c}& {5}& {4}& {3}& {2}& {1}\\ {d}& {7}& {6}& {5}& {4}& {3}\end{array}\right]$ (2)

We can get the same result if we specify the first column with its label, $A$.

 > $\mathrm{select}\left(\mathrm{isprime},\mathrm{df},A\right)$
 $\left[\begin{array}{cccccc}{}& {A}& {B}& {C}& {\mathrm{D}}& {E}\\ {b}& {3}& {2}& {1}& {0}& {-1}\\ {c}& {5}& {4}& {3}& {2}& {1}\\ {d}& {7}& {6}& {5}& {4}& {3}\end{array}\right]$ (3)

A third way to get the same result is by indexing with a Boolean DataSeries.

 > $\mathrm{df}\left[\mathrm{~}\left[\mathrm{isprime}\right]\left(\mathrm{df}\left[A\right]\right)\right]$
 $\left[\begin{array}{cccccc}{}& {A}& {B}& {C}& {\mathrm{D}}& {E}\\ {b}& {3}& {2}& {1}& {0}& {-1}\\ {c}& {5}& {4}& {3}& {2}& {1}\\ {d}& {7}& {6}& {5}& {4}& {3}\end{array}\right]$ (4)

We can obtain the rows where the entries in column $\mathrm{D}$ are non-prime using remove.

 > $\mathrm{remove}\left(\mathrm{isprime},\mathrm{df},\mathrm{D}\right)$
 $\left[\begin{array}{cccccc}{}& {A}& {B}& {C}& {\mathrm{D}}& {E}\\ {a}& {1}& {0}& {-1}& {-2}& {-3}\\ {b}& {3}& {2}& {1}& {0}& {-1}\\ {d}& {7}& {6}& {5}& {4}& {3}\end{array}\right]$ (5)

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$.

 > $\mathrm{selectremove}\left(\mathrm{isprime},\mathrm{df},C\right)$
 $\left[\begin{array}{cccccc}{}& {A}& {B}& {C}& {\mathrm{D}}& {E}\\ {c}& {5}& {4}& {3}& {2}& {1}\\ {d}& {7}& {6}& {5}& {4}& {3}\end{array}\right]{,}\left[\begin{array}{cccccc}{}& {A}& {B}& {C}& {\mathrm{D}}& {E}\\ {a}& {1}& {0}& {-1}& {-2}& {-3}\\ {b}& {3}& {2}& {1}& {0}& {-1}\end{array}\right]$ (6)

If we want to select the entries of a particular type, then we can use the optional fourth argument to select.

 > $\mathrm{select}\left(\mathrm{type},\mathrm{df},C,\mathrm{positive}\right)$
 $\left[\begin{array}{cccccc}{}& {A}& {B}& {C}& {\mathrm{D}}& {E}\\ {b}& {3}& {2}& {1}& {0}& {-1}\\ {c}& {5}& {4}& {3}& {2}& {1}\\ {d}& {7}& {6}& {5}& {4}& {3}\end{array}\right]$ (7)

The original DataFrame, $\mathrm{df}$, is unchanged, because we used the commands without the inplace index.

 > $\mathrm{df}$
 $\left[\begin{array}{cccccc}{}& {A}& {B}& {C}& {\mathrm{D}}& {E}\\ {a}& {1}& {0}& {-1}& {-2}& {-3}\\ {b}& {3}& {2}& {1}& {0}& {-1}\\ {c}& {5}& {4}& {3}& {2}& {1}\\ {d}& {7}& {6}& {5}& {4}& {3}\end{array}\right]$ (8)

If we call select with the inplace index, then $\mathrm{df}$ is modified in-place.

 > $\mathrm{select}\left[\mathrm{inplace}\right]\left(\mathrm{type},\mathrm{df},C,\mathrm{positive}\right)$
 $\left[\begin{array}{cccccc}{}& {A}& {B}& {C}& {\mathrm{D}}& {E}\\ {b}& {3}& {2}& {1}& {0}& {-1}\\ {c}& {5}& {4}& {3}& {2}& {1}\\ {d}& {7}& {6}& {5}& {4}& {3}\end{array}\right]$ (9)
 > $\mathrm{df}$
 $\left[\begin{array}{cccccc}{}& {A}& {B}& {C}& {\mathrm{D}}& {E}\\ {b}& {3}& {2}& {1}& {0}& {-1}\\ {c}& {5}& {4}& {3}& {2}& {1}\\ {d}& {7}& {6}& {5}& {4}& {3}\end{array}\right]$ (10)

Compatibility

 • The DataFrame/select, DataFrame/remove and DataFrame/selectremove commands were introduced in Maple 2019.