Find Unique Rows - Maple Help

DataFrame/AreUnique

determine unique rows in a DataFrame

 Calling Sequence AreUnique( data )

Parameters

 data - options - options : (optional) equation(s) of the form option=value where option can be keep.

Options

 • keep : first, last, none;  if a duplicate row is encountered, keep specifies which duplicate row to mark as unique

Description

 • The AreUnique command returns a DataSeries of type truefalseFAIL, where the elements correspond to true if the corresponding row is unique and false if the given row is a duplicate of another row in the given DataFrame.
 • The output from the AreUnique command can be used to index a DataSeries or DataFrame in order to return the unique rows.
 • The keep option controls how duplicate rows are handled. By default, keep marks the first instance of a row as unique (true) and marks all repeated rows of any previously marked unique rows as duplicate (false). If keep is set to last, the last detected duplicate row is marked as unique and all other repeated rows are marked as duplicates. If keep is set to none, all rows that have duplicates are marked as duplicate (false).

Examples

The following DataFrame has one duplicate row; the fourth row is the same as the first.

 > $\mathrm{DF}≔\mathrm{DataFrame}\left(⟨⟨1,1,2,1,3,4⟩|⟨6,5,1,6,9,9⟩|⟨4,2,1,4,8,3⟩⟩\right)$
 ${\mathrm{DF}}{≔}\left[\begin{array}{cccc}{}& {1}& {2}& {3}\\ {1}& {1}& {6}& {4}\\ {2}& {1}& {5}& {2}\\ {3}& {2}& {1}& {1}\\ {4}& {1}& {6}& {4}\\ {5}& {3}& {9}& {8}\\ {6}& {4}& {9}& {3}\end{array}\right]$ (1)

The AreUnique command returns a truefalseFAIL DataSeries that shows duplicate rows as false and unique rows as true.

 > $\mathrm{AreUnique}\left(\mathrm{DF}\right)$
 $\left[\begin{array}{cc}{1}& {\mathrm{true}}\\ {2}& {\mathrm{true}}\\ {3}& {\mathrm{true}}\\ {4}& {\mathrm{false}}\\ {5}& {\mathrm{true}}\\ {6}& {\mathrm{true}}\end{array}\right]$ (2)

If the DataFrame is indexed by the result, a filtered DataFrame is returned that removes any duplicate rows:

 > $\mathrm{DF}\left[\mathrm{AreUnique}\left(\mathrm{DF}\right)\right]$
 $\left[\begin{array}{cccc}{}& {1}& {2}& {3}\\ {1}& {1}& {6}& {4}\\ {2}& {1}& {5}& {2}\\ {3}& {2}& {1}& {1}\\ {5}& {3}& {9}& {8}\\ {6}& {4}& {9}& {3}\end{array}\right]$ (3)

The keep option allows for specification of which row to keep (either the first, last or none) when a duplicate row is found:

 > $\mathrm{DF}\left[\mathrm{AreUnique}\left(\mathrm{DF},\mathrm{keep}=\mathrm{first}\right)\right]$
 $\left[\begin{array}{cccc}{}& {1}& {2}& {3}\\ {1}& {1}& {6}& {4}\\ {2}& {1}& {5}& {2}\\ {3}& {2}& {1}& {1}\\ {5}& {3}& {9}& {8}\\ {6}& {4}& {9}& {3}\end{array}\right]$ (4)
 > $\mathrm{DF}\left[\mathrm{AreUnique}\left(\mathrm{DF},\mathrm{keep}=\mathrm{last}\right)\right]$
 $\left[\begin{array}{cccc}{}& {1}& {2}& {3}\\ {2}& {1}& {5}& {2}\\ {3}& {2}& {1}& {1}\\ {4}& {1}& {6}& {4}\\ {5}& {3}& {9}& {8}\\ {6}& {4}& {9}& {3}\end{array}\right]$ (5)

If keep is set to none, any row that has a duplicate is marked as a duplicate (false).

 > $\mathrm{DF}\left[\mathrm{AreUnique}\left(\mathrm{DF},\mathrm{keep}=\mathrm{none}\right)\right]$
 $\left[\begin{array}{cccc}{}& {1}& {2}& {3}\\ {2}& {1}& {5}& {2}\\ {3}& {2}& {1}& {1}\\ {5}& {3}& {9}& {8}\\ {6}& {4}& {9}& {3}\end{array}\right]$ (6)

The AreUnique command can also be used on individual DataSeries in a DataFrame. This allows for the removal of the rows that have duplicate values in a specific column.

 > $\mathrm{DF}\left[\mathrm{AreUnique}\left(\mathrm{DF}\left[1\right],\mathrm{keep}=\mathrm{first}\right)\right]$
 $\left[\begin{array}{cccc}{}& {1}& {2}& {3}\\ {1}& {1}& {6}& {4}\\ {3}& {2}& {1}& {1}\\ {5}& {3}& {9}& {8}\\ {6}& {4}& {9}& {3}\end{array}\right]$ (7)

Compatibility

 • The DataFrame/AreUnique command was introduced in Maple 2016.