DataFrame#

class ampl.DataFrame : IEnumerable#

A DataFrame object, used to communicate data to and from the AMPL entities.

An object of this class can be used to do the following tasks:

Assign values to AMPL entities (once the DataFrame is populated, use ampl.AMPL.SetData to assign its values to the modelling entities in its columns)

Get values from AMPL, decoupling the values from the AMPL entities they originate via ampl.Entities.Entity.GetValues.

A DataFrame object can be created in various ways via the various constructors: create a skeleton manually specifiying the number of indexing columns and the column headers; get column names (and number of indexing columns) from entities of the API passing them directly to the appropriate constructor, get values from AMPL, decoupling the values from the AMPL entities they originate from (via ampl.Entities.Entity.GetValues()).

Populating a DataFrame object can be done adding row by row to a pre-existing skeleton via ampl.DataFrame.AddRow, setting whole columns of a pre-existing skeleton via ampl.DataFrame.SetColumn or adding columns (including indexing columns) via ampl.DataFrame.AddColumn. Modifying a DataFrame object can be done via ampl.DataFrame.SetColumn or via ampl.DataFrame.SetArray or ampl.DataFrame.SetMatrix Accessing data in a DataFrame can be done row by row using ampl.DataFrame.GetRow or by column via ampl.DataFrame.GetColumn.

Public Functions

DataFrame (int numberOfIndexColumns)#

Create a new DataFrame with the specified number of indices.

Param numberOfIndexColumns:

DataFrame (int numberOfIndexColumns, params string[] headers)

Create a new DataFrame with the specified number of indices and the specified headers.

Param numberOfIndexColumns:

Number of columns to be considered as index for this table (>=0)

Param headers:

Headers (column names)

DataFrame (params ampl.Entities.EntityBase[] headers)

Create a new DataFrame with the specified entities as column headers.

Param headers:

The columns headers to be used; since they are AMPL entities, sets are automatically considered indices and have to be placed first in the constructor.

void AddRow (Tuple value)#

Add a row to the DataFrame.

The size of the tuple must be equal to the total number of columns in the dataframe.

Param value:

A tuple containing all the values for the row to be added

void AddRow (params object[] values)

Add a row to the DataFrame.

The size of the tuple must be equal to the total number of columns in the dataframe.

Param values:

A collectiong containing all the values for the row to be added

void AddRow (VariantRef a1)

Add a value to a DataFrame composed of only one column.

Param a1:

The value to add

void AddRow (VariantRef a1, VariantRef a2)

Add a value to a DataFrame composed of two columns.

Param a1:

Value for the first column

Param a2:

Value for the second column

void AddRow (VariantRef a1, VariantRef a2, VariantRef a3)

Add a value to a DataFrame composed of two columns.

Param a1:

Value for the first column

Param a2:

Value for the second column

Param a3:

Value for the third column

void AddRow (VariantRef a1, VariantRef a2, VariantRef a3, VariantRef a4)

Add a value to a DataFrame composed of two columns.

Param a1:

Value for the first column

Param a2:

Value for the second column

Param a3:

Value for the third column

Param a4:

Value for the fourth column

void AddColumn (string header)#

Add a new empty column with the corresponding header.

Param header:

The header

void AddColumn (string header, double[] values)

Add a new column with the corresponding header and values to the dataframe.

Param header:

The name of the new column

Param values:

An array of size NumRows with all the values of the new column

void AddColumn (string header, string[] values)

Add a new column with the corresponding header and values to the dataframe.

Param header:

The name of the new column

Param values:

An array of size NumRows with all the values of the new column

Column GetColumn (string header)#

Get the specified column as a view object.

Param header:

The column name

void SetColumn (string header, params double[] values)#

Set the values of a column.

Param header:

The header of the column to be set

Param values:

The values to be set

void SetColumn (string header, params string[] values)

Set the values of a column.

Param header:

The header of the column to be set

Param values:

The values to be set

Row GetRowByIndex (int index)#

Get row by numeric index.

Param index:

Zero-based index of the row to get

Return:

Corresponding row

Row GetRow (params object[] index)#

Get a row by value of the indexing columns.

If the index is not specified, gets the only row of a dataframe with no indexing columns.

Param index:

Collection of objects representing the index of the desired row

Row GetRow (Tuple index)

Get a row by value of the indexing columns.

If the index is not specified, gets the only row of a dataframe with no indexing columns.

Param index:

Tuple representing the index of the desired row

string[] GetHeaders ()#

Get headers of all columns.

void Reserve (int numRows)#

Reserve space for the given number of rows.

NOTE that the rows cannot be accessed, they still have to be added via DataFrame.AddRow.

Param numRows:

Number of rows to be resetved

override string ToString ()#

Return a tabular string representation of the dataframe object.

void SetArray (double[] indices, double[] values)#

Set the values of a DataFrame from an array of doubles.

The DataFrame must have one index and one data column.

Param indices:

The indices of the values to set

Param values:

An array containing the values to be set

void SetArray (string[] indices, double[] values)

Set the values of a DataFrame from an array of doubles.

The DataFrame must have one index and one data column.

Param indices:

The indices of the values to set

Param values:

An array containing the values to be set

void SetArray (string[] indices, string[] values)

Set the values of a DataFrame from an array of strings.

The DataFrame must have one index and one data column.

Param indices:

The indices of the values to set

Param values:

An array containing the values to be set

void SetArray (double[] indices, string[] values)

Set the values of a DataFrame from an array of strings.

The DataFrame must have one index and one data column.

Param indices:

The indices of the values to set

Param values:

An array containing the values to be set

void SetMatrix (double[] indices0, double[] indices1, double[,] values)#

Set a matrix of doubles to an empty DataFrame.

The DataFrame must have two indices and one data column.

Param indices0:

The values of the first indexing column

Param indices1:

The values of the second indexing column

Param values:

A 2d-array of doubles

void SetMatrix (double[] indices0, string[] indices1, double[,] values)

Set a matrix of doubles to an empty DataFrame.

The DataFrame must have two indices and one data column.

Param indices0:

The values of the first indexing column

Param indices1:

The values of the second indexing column

Param values:

A 2d-array of doubles

void SetMatrix (string[] indices0, double[] indices1, double[,] values)

Set a matrix of doubles to an empty DataFrame.

The DataFrame must have two indices and one data column.

Param indices0:

The values of the first indexing column

Param indices1:

The values of the second indexing column

Param values:

A 2d-array of doubles

void SetMatrix (string[] indices0, string[] indices1, double[,] values)

Set a matrix of doubles to an empty DataFrame.

The DataFrame must have two indices and one data column.

Param indices0:

The values of the first indexing column

Param indices1:

The values of the second indexing column

Param values:

A 2d-array of doubles

void SetMatrix (double[] indices0, double[] indices1, string[,] values)

Set a matrix of strings to an empty DataFrame.

The DataFrame must have two indices and one data column.

Param indices0:

The values of the first indexing column

Param indices1:

The values of the second indexing column

Param values:

A 2d-array of strings

void SetMatrix (double[] indices0, string[] indices1, string[,] values)

Set a matrix of strings to an empty DataFrame.

The DataFrame must have two indices and one data column.

Param indices0:

The values of the first indexing column

Param indices1:

The values of the second indexing column

Param values:

A 2d-array of strings

void SetMatrix (string[] indices0, double[] indices1, string[,] values)

Set a matrix of strings to an empty DataFrame.

The DataFrame must have two indices and one data column.

Param indices0:

The values of the first indexing column

Param indices1:

The values of the second indexing column

Param values:

A 2d-array of strings

void SetMatrix (string[] indices0, string[] indices1, string[,] values)

Set a matrix of strings to an empty DataFrame.

The DataFrame must have two indices and one data column.

Param indices0:

The values of the first indexing column

Param indices1:

The values of the second indexing column

Param values:

A 2d-array of strings

IEnumerator<Row> GetEnumerator ()#
override bool Equals (object obj)#
override int GetHashCode ()#

Properties

int NumCols { get; set; }#

Get the total number of columns in this dataframe (indexarity + number of values)

int NumRows { get; set; }#

Get the number of data rows in this dataframe.

int NumIndices { get; set; }#

Get the number of indices (indexarity) of this dataframe.

this[params object[] index { get; set; }#

Get the row corresponding to the specified index.

class Column : public IEnumerable#

Public Functions

IEnumerator<VariantRef> GetEnumerator ()#

Properties

VariantRef this[int index] {get;set;}
int Size { get; set; }#
class Row : public IEnumerable#

Public Functions

IEnumerator<VariantRef> GetEnumerator ()#

Properties

VariantRef this[int index] {get;set;}
int Size { get; set; }#