Remove Columns or Rows - Maple Help

DataFrame/Remove

remove columns or rows in a DataFrame

 Calling Sequence Remove( df, index, options )

Parameters

 df - index - name, string, integer or list; specifies the index of the column (or columns) to remove from the DataFrame

Options

 • mode : name; specifies whether to remove columns or rows. The default is column. This option is entered in the form mode = m, where m is one of column, columns, row, or rows.

Description

 • The Remove command removes a chosen column or row or a list of columns or rows from a DataFrame.

Examples

The Remove command is used to remove columns from a DataFrame:

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

The following removes the second column of the DataFrame:

 > $\mathrm{Remove}\left(\mathrm{df},2\right)$
 ${2}$
 $\left[\begin{array}{ccc}{}& {1}& {3}\\ {1}& {1}& {3}\\ {2}& {4}& {6}\\ {3}& {7}& {9}\end{array}\right]$ (2)

It is also possible to remove multiple columns of a DataFrame:

 > $\mathrm{Remove}\left(\mathrm{df},\left[2,3\right]\right)$
 $\left[\begin{array}{cc}{2}& {3}\end{array}\right]$
 $\left[\begin{array}{cc}{}& {1}\\ {1}& {1}\\ {2}& {4}\\ {3}& {7}\end{array}\right]$ (3)

It is possible to remove rows in a DataFrame using the mode option:

 > $\mathrm{Remove}\left(\mathrm{df},1,\mathrm{mode}=\mathrm{row}\right)$
 ${1}$
 $\left[\begin{array}{cccc}{}& {1}& {2}& {3}\\ {2}& {4}& {5}& {6}\\ {3}& {7}& {8}& {9}\end{array}\right]$ (4)

The Remove command does not act inplace. In order to permanently remove a column, reassignment is needed.

 > $\mathrm{df}≔\mathrm{Remove}\left(\mathrm{df},3\right)$
 ${3}$
 ${\mathrm{df}}{≔}\left[\begin{array}{ccc}{}& {1}& {2}\\ {1}& {1}& {2}\\ {2}& {4}& {5}\\ {3}& {7}& {8}\end{array}\right]$ (5)

The Remove command is helpful when dealing with DataFrames that have a mixture of non-numeric and numeric columns. For example, the Iris data set has 4 columns of numeric data and one column of strings.

 > $\mathrm{IrisData}≔\mathrm{Import}\left("datasets/iris.csv",\mathrm{base}=\mathrm{datadir}\right)$

Attempting to plot or run any statistical analysis on this dataset as is will often result in an error due to the non-numeric data. Removing the non-numeric data for analysis avoids this issue.

 > $\mathrm{Statistics}:-\mathrm{BoxPlot}\left(\mathrm{Remove}\left(\mathrm{IrisData},\mathrm{Species}\right),\mathrm{size}=\left[600,"golden"\right]\right)$
 ${5}$

Compatibility

 • The DataFrame/Remove command was introduced in Maple 2017.