DataFrame Constructor - Maple Help

DataFrame

create a DataFrame from data

 Calling Sequence DataFrame( L, opts ) DataFrame( ds1, ds2, ..., opts ); DataFrame( label1 = ds1, label2 = ds2, ..., opts ); DataFrame( T, opts );

Parameters

 L - : {listlist,list(DataSeries),Array,Matrix,DataFrame,table} : input data ds1, ds2, ... - : DataSeries : columns from existing DataSeries label1, label2, ... - column labels to use T - : table : data specification in table form

Options

 • rows : {list,Array,Vector}, labels to use for the rows of data
 • columns : {list,Array,Vector}, labels to use for the columns of data
 • datatypes : list(type), types for the columns of data

Description

 • The DataFrame constructor produces a DataFrame data container, from the input data in various forms.
 • The input data (L) may be a list of columns for the resulting DataFrame. The individual columns in L may be specified as lists, one-dimensional rtables (Arrays, Vectors), or DataSeries objects.
 • You can also specify the data as a two-dimensional rtable (Matrix or Array) L, in which case the rows and columns of L are used respectively as the rows and columns of data for the DataFrame.
 • A sequence ds1, ds2, ... of DataSeries objects may be passed, and these are used as the columns of the resulting DataFrame.
 • A sequence of equations of the form label = ds can be passed to simultaneously specify the columns of data, from the DataSeries ds, and corresponding column labels label.
 • If the input T is a table, then the indices of T are used as the column labels, while the entries of T are used as the data items for the corresponding columns. Note that in this case, there is no pre-determined order for the columns.
 • The input L may be an existing DataFrame, in which case you can use the constructor to produce a new DataFrame with different (compatible) data types, or to re-label the data items.

Examples

 > $\mathrm{DataFrame}\left(⟨⟨⟨1|2|3⟩,⟨4|5|6⟩⟩⟩\right)$
 $\left[\begin{array}{cccc}{}& {1}& {2}& {3}\\ {1}& {1}& {2}& {3}\\ {2}& {4}& {5}& {6}\end{array}\right]$ (1)
 > $\mathrm{df}≔\mathrm{DataFrame}\left(⟨⟨⟨1|2|3⟩,⟨4|5|6⟩⟩⟩,'\mathrm{rows}'=\left['a','b'\right],'\mathrm{columns}'=\left['A','B','C'\right]\right)$
 ${\mathrm{df}}{≔}\left[\begin{array}{cccc}{}& {A}& {B}& {C}\\ {a}& {1}& {2}& {3}\\ {b}& {4}& {5}& {6}\end{array}\right]$ (2)
 > $\mathrm{df}\left['A'\right]$
 $\left[\begin{array}{cc}{a}& {1}\\ {b}& {4}\end{array}\right]$ (3)
 > $\mathrm{type}\left(\mathrm{df}\left['A'\right],\mathrm{DataSeries}\right)$
 ${\mathrm{true}}$ (4)
 > $\mathrm{DataFrame}\left(⟨⟨⟨1|2|3⟩,⟨4|5|6⟩⟩⟩,'\mathrm{rows}'=\left['a','b'\right],'\mathrm{columns}'=\left['A','B','C'\right],'\mathrm{datatypes}'=\left['\mathrm{integer}'\left[4\right],'\mathrm{integer}'\left[4\right],'\mathrm{integer}'\left[2\right]\right]\right)$
 $\left[\begin{array}{cccc}{}& {A}& {B}& {C}\\ {a}& {1}& {2}& {3}\\ {b}& {4}& {5}& {6}\end{array}\right]$ (5)
 > $\mathrm{DataFrame}\left(\left[\left[1,2,3\right],\left[4,5,6\right]\right]\right)$
 $\left[\begin{array}{ccc}{}& {1}& {2}\\ {1}& {1}& {4}\\ {2}& {2}& {5}\\ {3}& {3}& {6}\end{array}\right]$ (6)
 > $\mathrm{DataFrame}\left(\left[\left[1,2\right],\left[3,4\right],\left[5,6\right]\right]\right)$
 $\left[\begin{array}{cccc}{}& {1}& {2}& {3}\\ {1}& {1}& {3}& {5}\\ {2}& {2}& {4}& {6}\end{array}\right]$ (7)

The numbers of elements in each column must be the same.

 > $\mathrm{DataFrame}\left(\left[\left[1,2\right],\left[3,4,5\right]\right]\right)$
 > $\mathrm{DataFrame}\left(\mathrm{df},'\mathrm{rows}'=\left['c','d'\right]\right)$
 $\left[\begin{array}{cccc}{}& {A}& {B}& {C}\\ {c}& {1}& {2}& {3}\\ {d}& {4}& {5}& {6}\end{array}\right]$ (8)
 > $\mathrm{DataFrame}\left(\mathrm{df},'\mathrm{columns}'=\left['\mathrm{First}','\mathrm{Second}','\mathrm{Third}'\right]\right)$
 $\left[\begin{array}{cccc}{}& {\mathrm{First}}& {\mathrm{Second}}& {\mathrm{Third}}\\ {a}& {1}& {2}& {3}\\ {b}& {4}& {5}& {6}\end{array}\right]$ (9)
 > $\mathrm{DataFrame}\left(\mathrm{df},'\mathrm{rows}'=\left['\mathrm{above}','\mathrm{below}'\right],'\mathrm{columns}'=\left['\mathrm{First}','\mathrm{Second}','\mathrm{Third}'\right]\right)$
 $\left[\begin{array}{cccc}{}& {\mathrm{First}}& {\mathrm{Second}}& {\mathrm{Third}}\\ {\mathrm{above}}& {1}& {2}& {3}\\ {\mathrm{below}}& {4}& {5}& {6}\end{array}\right]$ (10)
 > $\mathrm{ds1}≔\mathrm{DataSeries}\left(\left[1,2,3\right]\right)$
 ${\mathrm{ds1}}{≔}\left[\begin{array}{cc}{1}& {1}\\ {2}& {2}\\ {3}& {3}\end{array}\right]$ (11)
 > $\mathrm{ds2}≔\mathrm{DataSeries}\left(\left[4,5,6\right]\right)$
 ${\mathrm{ds2}}{≔}\left[\begin{array}{cc}{1}& {4}\\ {2}& {5}\\ {3}& {6}\end{array}\right]$ (12)
 > $\mathrm{DataFrame}\left(\mathrm{ds1},\mathrm{ds2}\right)$
 $\left[\begin{array}{ccc}{}& {1}& {2}\\ {1}& {1}& {4}\\ {2}& {2}& {5}\\ {3}& {3}& {6}\end{array}\right]$ (13)
 > $\mathrm{DataFrame}\left(\left[\mathrm{ds1},\mathrm{ds2}\right]\right)$
 $\left[\begin{array}{ccc}{}& {1}& {2}\\ {1}& {1}& {4}\\ {2}& {2}& {5}\\ {3}& {3}& {6}\end{array}\right]$ (14)
 > $\mathrm{DataFrame}\left(\mathrm{ds1},\mathrm{ds2},'\mathrm{columns}'=\left['A','B'\right]\right)$
 $\left[\begin{array}{ccc}{}& {A}& {B}\\ {1}& {1}& {4}\\ {2}& {2}& {5}\\ {3}& {3}& {6}\end{array}\right]$ (15)

Compatibility

 • The DataFrame command was introduced in Maple 2016.