Libraries.Compute.Statistics.DataFrame Documentation

The DataFrame class is a collection of columns and rows, like a spreadsheet, that can be used for statistics and other calculations. By default, it can load comma separated files. Other file types can be supported using the Load action with a file loader for the custom type. DataFrame objects can also be transformed using the Transform action, which is useful for sorting, filtering, or other operations. Transforms generally make a copy of the data frame and act on that copy, not the original.

Example Code

use Libraries.Compute.Statistics.DataFrame

    //Load a comma separated file
    DataFrame frame
    frame:Load("Data.csv")

Inherits from: Libraries.Language.Object

Summary

Actions Summary Table

ActionsDescription
Calculate(Libraries.Compute.Statistics.DataFrameCalculation calculation)This action runs a calculation on the data frame.
Compare(Libraries.Language.Object object)This action compares two object hash codes and returns an integer.
ConvertToMatrix()This action takes a DataFrame and converts it into a matrix with number values.
Copy()This action returns a copy of the data frame, which deep copies every column.
Copy(integer columnStart, integer columnEnd, integer rowStart, integer rowEnd)Returns a copy of the data frame, except that it only copies certain columns and rows
CreateChart(Libraries.Compute.Statistics.DataFrameChartCreator creator)This action creates a chart, given a particular DataFrameChartCreator instance and returns a chart from it for this particular data.
Equals(Libraries.Language.Object object)This action determines if two objects are equal based on their hash code values.
GetColumn(text header)This action returns the first column with the name "header" in its header row.
GetColumn(integer index)This action obtains a column from the DataFrame.
GetColumns()This action gets the columns in the DataFrame.
GetHashCode()This action gets the hash code for an object.
GetSize()This action returns the number of columns in the data frame.
IsEmpty()This action returns true if the number of columns is zero
Load(Libraries.System.File file, Libraries.Compute.Statistics.DataFrameLoader loader)This action loads data from a file and then places it into the existing data frame.
Load(Libraries.System.File file)This action loads a data frame from a file.
Load(text location)This action loads a data frame from a file relative to the working directory, which is typically where the executable lives.
SetColumns(Libraries.Containers.Array<Libraries.Compute.Statistics.DataFrameColumn> columns)This action replaces the columns in the DataFrame.
Transform(Libraries.Compute.Statistics.DataFrameTransform transform)This action takes the data from the current DataFrame then transforms into a copy of this data frame.

Actions Documentation

Calculate(Libraries.Compute.Statistics.DataFrameCalculation calculation)

This action runs a calculation on the data frame. Calculations are not intended to be destructive to the original data.

Example Code

use Libraries.Compute.Statistics.DataFrame
        use Libraries.System.File

        //Load a comma separated file
        DataFrame frame
        File file
        file:SetPath("Data.csv")
        frame:Load(file)

Parameters

Compare(Libraries.Language.Object object)

This action compares two object hash codes and returns an integer. The result is larger if this hash code is larger than the object passed as a parameter, smaller, or equal. In this case, -1 means smaller, 0 means equal, and 1 means larger. This action was changed in Quorum 7 to return an integer, instead of a CompareResult object, because the previous implementation was causing efficiency issues.

Example Code

Object o
        Object t
        integer result = o:Compare(t) //1 (larger), 0 (equal), or -1 (smaller)

Parameters

Return

integer: The Compare result, Smaller, Equal, or Larger.

ConvertToMatrix()

This action takes a DataFrame and converts it into a matrix with number values. If the data frame contains columns that cannot be converted to numbers, this action throws an exception. Finally, all columns must have the same size for this conversion to work.

Example Code

use Libraries.Compute.Statistics.DataFrame
        use Libraries.Compute.Matrix

        //Load a comma separated file
        DataFrame frame
        frame:Load("Data.csv")

        //reverse the data frame
        Matrix matrix = frame:ConvertToMatrix()
        output matrix:ToText()

Return

Libraries.Compute.Matrix: A matrix of real number values

Copy()

This action returns a copy of the data frame, which deep copies every column.

Example Code

use Libraries.Compute.Statistics.DataFrame

        //Load a comma separated file
        DataFrame frame
        frame:Load("Data.csv")

        //return a copy of the entire DataFrame
        DataFrame copy = frame:Copy()

Return

Libraries.Compute.Statistics.DataFrame: A copy of the data frame with constrained columns and rows

Copy(integer columnStart, integer columnEnd, integer rowStart, integer rowEnd)

Returns a copy of the data frame, except that it only copies certain columns and rows

Example Code

use Libraries.Compute.Statistics.DataFrame

        //Load a comma separated file
        DataFrame frame
        frame:Load("Data.csv")

        //return a copy with a max of the first five rows
        DataFrame copy = frame:Copy(0, frame:GetSize(), 0, 5)

Parameters

Return

Libraries.Compute.Statistics.DataFrame: A copy of the data frame with constrained columns and rows

CreateChart(Libraries.Compute.Statistics.DataFrameChartCreator creator)

This action creates a chart, given a particular DataFrameChartCreator instance and returns a chart from it for this particular data.

Example Code

use Libraries.Compute.Statistics.DataFrame
        use Libraries.Compute.Statistics.Charts.BarChartCreator
        use Libraries.System.File

        //Load a comma separated file
        DataFrame frame
        frame:Load("Data.csv")

        //We might instantiate an object to create a bar chart, setting some properties if we want to
        BarChartCreator create
        frame:CreateChart(create)

Parameters

Return

Libraries.Interface.Controls.Charts.Chart: A chart object, which can be embedded into a user interface

Equals(Libraries.Language.Object object)

This action determines if two objects are equal based on their hash code values.

Example Code

use Libraries.Language.Object
        use Libraries.Language.Types.Text
        Object o
        Text t
        boolean result = o:Equals(t)

Parameters

Return

boolean: True if the hash codes are equal and false if they are not equal.

GetColumn(text header)

This action returns the first column with the name "header" in its header row. If multiple columns have the same name, then to get them all, you will need to iterate and find each one using GetColumn(integer) instead.

Example Code

use Libraries.Compute.Statistics.DataFrame

        //Load a comma separated file
        DataFrame frame
        frame:Load("Data.csv") 
        DataFrameColumn column = frame:GetColumn("Gender")

Parameters

Return

Libraries.Compute.Statistics.DataFrameColumn: the column, possibly undefined if no column of that name exists

GetColumn(integer index)

This action obtains a column from the DataFrame. This column is the original, not a copy, so modifications made to the column will be permanent. If the goal is to obtain a copy, then either the Copy actions or the Transform classes should be used.

Example Code

use Libraries.Compute.Statistics.DataFrame

        //Load a comma separated file
        DataFrame frame
        frame:Load("Data.csv") 
        DataFrameColumn column = frame:GetColumn(0)

Parameters

Return

Libraries.Compute.Statistics.DataFrameColumn:

GetColumns()

This action gets the columns in the DataFrame. This allows direct control of the columns for this particular data frame. We suggest not using these values directly unless required by an application.

Example Code

use Libraries.Compute.Statistics.DataFrame

        //Load a comma separated file
        DataFrame frame
        frame:Load("Data.csv") 
        Array<DataFrameColumn> col = frame:GetColumns()

Return

Libraries.Containers.Array:

GetHashCode()

This action gets the hash code for an object.

Example Code

Object o
        integer hash = o:GetHashCode()

Return

integer: The integer hash code of the object.

GetSize()

This action returns the number of columns in the data frame. This value is not related to the number of rows in any particular column.

Example Code

use Libraries.Compute.Statistics.DataFrame

        //Load a comma separated file
        DataFrame frame
        frame:Load("Data.csv") 
        output frame:GetSize()

Return

integer: the number of columns in the DataFrame.

IsEmpty()

This action returns true if the number of columns is zero

Example Code

use Libraries.Compute.Statistics.DataFrame

        //Load a comma separated file
        DataFrame frame
        frame:Load("Data.csv") 
        output frame:IsEmpty()

Return

boolean: true if the number of columns is zero.

Load(Libraries.System.File file, Libraries.Compute.Statistics.DataFrameLoader loader)

This action loads data from a file and then places it into the existing data frame. If data already exists in this data frame, it is discarded and replaced.

Example Code

use Libraries.Compute.Statistics.DataFrame
        use Libraries.Compute.Statistics.Loaders.CommaSeparatedLoader
        use Libraries.System.File

        //Load a comma separated file
        DataFrame frame
        File file
        file:SetPath("Data.csv")
        CommaSeparatedLoader loader
        frame:Load(file, loader)

Parameters

Load(Libraries.System.File file)

This action loads a data frame from a file.

Example Code

use Libraries.Compute.Statistics.DataFrame
        use Libraries.System.File

        //Load a comma separated file
        DataFrame frame
        File file
        file:SetPath("Data.csv")
        frame:Load(file)

Parameters

Load(text location)

This action loads a data frame from a file relative to the working directory, which is typically where the executable lives.

Example Code

use Libraries.Compute.Statistics.DataFrame

        //Load a comma separated file
        DataFrame frame
        frame:Load("Data.csv")

Parameters

SetColumns(Libraries.Containers.Array<Libraries.Compute.Statistics.DataFrameColumn> columns)

This action replaces the columns in the DataFrame. It is needed by the Loader infrastructure in order to change the columns. However, for most users, the Transform infrastructure should be used instead of adjusting these manually. In other words, do not use this action unless you know what you are doing.

Example Code

use Libraries.Compute.Statistics.DataFrame

        //Load a comma separated file
        DataFrame frame
        frame:Load("Data.csv") 
        Array<DataFrameColumn> col
        frame:SetColumns(col)

Parameters

Transform(Libraries.Compute.Statistics.DataFrameTransform transform)

This action takes the data from the current DataFrame then transforms into a copy of this data frame. While custom Transforms can choose to adjust the original, by default they do not.

Example Code

use Libraries.Compute.Statistics.DataFrame
        use Libraries.Compute.Statistics.Transforms.ReverseTransform
        use Libraries.System.File

        //Load a comma separated file
        DataFrame frame
        frame:Load("Data.csv")

        //reverse the data frame
        ReverseTransform reverse
        frame:Transform(reverse)

Parameters

Return

Libraries.Compute.Statistics.DataFrame: Typically a copy of the DataFrame, transformed by the transformer.