Remove Columns or Rows - Maple Help

# Online Help

###### All Products    Maple    MapleSim

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)$
 ${\mathrm{IrisData}}{≔}\begin{array}{c}\left[\begin{array}{cccccc}{}& {\mathrm{Sepal Length}}& {\mathrm{Sepal Width}}& {\mathrm{Petal Length}}& {\mathrm{Petal Width}}& {\mathrm{Species}}\\ {1}& {5.1}& {3.5}& {1.4}& {0.2}& {"setosa"}\\ {2}& {4.9}& {3}& {1.4}& {0.2}& {"setosa"}\\ {3}& {4.7}& {3.2}& {1.3}& {0.2}& {"setosa"}\\ {4}& {4.6}& {3.1}& {1.5}& {0.2}& {"setosa"}\\ {5}& {5}& {3.6}& {1.4}& {0.2}& {"setosa"}\\ {6}& {5.4}& {3.9}& {1.7}& {0.4}& {"setosa"}\\ {7}& {4.6}& {3.4}& {1.4}& {0.3}& {"setosa"}\\ {8}& {5}& {3.4}& {1.5}& {0.2}& {"setosa"}\\ {9}& {4.4}& {2.9}& {1.4}& {0.2}& {"setosa"}\\ {10}& {4.9}& {3.1}& {1.5}& {0.1}& {"setosa"}\\ {⋮}& {⋮}& {⋮}& {⋮}& {⋮}& {⋮}\end{array}\right]\\ \hfill {\text{150 x 5 DataFrame}}\end{array}$ (6)

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.
 • For more information on Maple 2017 changes, see Updates in Maple 2017.

 See Also