Package tech.tablesaw.table
Class Relation
java.lang.Object
tech.tablesaw.table.Relation
- Direct Known Subclasses:
Table
,TableSlice
A tabular data structure like a table in a relational database, but not formally implementing the
relational algebra
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract Relation
addColumns
(Column<?>... cols) Adds the given columns to this Relation and returns the same relation.as()
Returns anTableConverter
that can convert this Relation to a two-dimensional matrix of primitive numeric valuesbooleanColumn
(int columnIndex) Returns the DoubleColumn at the given 0-based index if present.booleanColumn
(String columnName) Returns a BooleanColumn with the given name if it is present in this Relation.Returns all BooleanColumns in this Relation as an ArraycategoricalColumn
(int columnNumber) Returns the CategoricalColumn at the given 0-based index if present.categoricalColumn
(String columnName) Returns a CategoricalColumn with the given name if it is present in this Relation.categoricalColumns
(String... columnName) Returns the columns whose names are given in the input arrayabstract void
clear()
Clears all the dat in the relation, leaving the structure intactabstract Column<?>
column
(int columnIndex) Returns the column at columnIndex (0-based)Column<?>
Returns the column with the given columnName, ignoring caseabstract int
Returns the number of columns in the relationint
columnIndex
(String columnName) Returns the index of the column with the given columnNameabstract int
columnIndex
(Column<?> col) Returns the index of the given columnReturns a list containing the names of all the columns in this relationcolumns()
Returns a list of all the columns in the relationcolumns
(int... columnIndices) Returns the columns whose indices are given in the input arrayReturns the columns whose names are given in the input arraycolumnsOfType
(ColumnType type) Returns a list containing all the columns of the given type in this RelationDeprecated.for API name consistency.int[]
Returns an array of column widths for printing tablesboolean
containsColumn
(String columnName) Returns true if a column with the given name is in this Relationboolean
containsColumn
(Column<?> column) Returns true if the given column is in this RelationdateColumn
(int columnIndex) Returns the DateColumn at the given 0-based index if present.dateColumn
(String columnName) Returns a DateColumn with the given name if it is present in this Relation.Returns all DateColumns in this Relation as an ArraydateTimeColumn
(int columnIndex) Returns the DateTimeColumn at the given 0-based index if present.dateTimeColumn
(String columnName) Returns a DateTimeColumn with the given name if it is present in this Relation.Returns all DateTimeColumns in this Relation as an ArraydoubleColumn
(int columnIndex) Returns the DoubleColumn at the given 0-based index if present.doubleColumn
(String columnName) Returns a DoubleColumn with the given name if it is present in this Relation.abstract Table
first
(int nRows) Returns a new table containing the first n rows in this RelationfloatColumn
(int columnIndex) Returns the FloatColumn at the given 0-based index if present.floatColumn
(String columnName) Returns a FloatColumn with the given name if it is present in this Relation.get
(int r, int c) Returns the value at the given row and column indexesgetString
(int r, int columnIndex) Returns a string representation of the value at the given row and column indexesReturns a string representation of the value at the given row and column indexesgetUnformatted
(int r, int c) Returns a string representation of the value at the given row and column indexesinstantColumn
(int columnIndex) Returns the InstantColumn at the given 0-based index if present.instantColumn
(String columnName) Returns an InstantColumn with the given name if it is present in this Relation.Returns all InstantColumns in this Relation as an ArrayintColumn
(int columnIndex) Returns the IntColumn at the given 0-based index if present.Returns an IntColumn with the given name if it is present in this Relation.boolean
isEmpty()
Returns true if this relation has zero rows and false otherwise.longColumn
(int columnIndex) Returns the LongColumn at the given 0-based index if present.longColumn
(String columnName) Returns a LongColumn with the given name if it is present in this Relation.abstract String
name()
Returns the name of this relationnCol
(int columnIndex) Returns the column with the given name cast to a NumberColumnReturns the column with the given name cast to a NumberColumn.numberColumn
(int columnIndex) Returns the NumberColumn at the given index.numberColumn
(String columnName) Returns a NumericColumn with the given name if it is present in this Relation.NumericColumn<?>[]
Returns all the NumericColumns in this Relation as an ArrayList<NumericColumn<?>>
Returns all the NumericColumns in the relationList<NumericColumn<?>>
numericColumns
(int... columnIndices) Returns all the NumericColumns in the relationList<NumericColumn<?>>
numericColumns
(String... columnNames) Returns all the NumericColumns in the relationprint()
Returns a String containing a 'pretty-printed' representation of this table containing at most 20 rows.print
(int rowLimit) Returns a 'pretty-printed' string representation of at most rowLimit rows from this relation.printAll()
Returns a 'pretty-printed' string representation of this entire relation.removeColumns
(int... columnIndexes) Removes the columns at the given 0-based indices from this Relation and returns the same relation.removeColumns
(String... columnName) Removes the columns with the given namesfrom this Relation and returns the same relation.abstract Relation
removeColumns
(Column<?>... columns) Removes the given columns from this Relation and returns the same relation.abstract int
rowCount()
Returns the number of rows in the relationabstract Relation
Sets the name of this Relation and returns the same relation.shape()
Returns a string that tells how many rows and columns this relation hasshortColumn
(int columnIndex) Returns the ShortColumn at the given 0-based index if present.shortColumn
(String columnName) Returns a ShortColumn with the given name if it is present in this Relation.smile()
Returns anSmileConverter
that can convert this table to a format suitable for use with the Smile machine learning library.stringColumn
(int columnIndex) Returns the StringColumn at the given 0-based index if present.stringColumn
(String columnName) Returns a StringColumn with the given name if it is present in this Relation.Returns all the StringColumns in this Relation as an ArrayReturns the structure of the this relation as a 3-column Table, consisting of Index (an IntColumn), Column Name (a StringColumn), and Column Type (a StringColumn)summary()
Returns a table containing summary statistics for the columns in this RelationtextColumn
(int columnIndex) Returns the TextColumn at the given 0-based index if present.textColumn
(String columnName) Returns a TextColumn with the given name if it is present in this Relation.timeColumn
(int columnIndex) Returns the TimeColumn at the given 0-based index if present.timeColumn
(String columnName) Returns a TimeColumn with the given name if it is present in this Relation.Returns all TimeColumns in this Relation as an ArraytoString()
Returns a String containing a 'pretty-printed' representation of this table containing at most 20 rows.Returns an array of the column types of all columns in the relation, including duplicates as appropriate, and maintaining ordertypes()
Returns a List of the column types of all columns in the relation, including duplicates as appropriate, and maintaining orderMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, iterator, spliterator
-
Constructor Details
-
Relation
public Relation()
-
-
Method Details
-
addColumns
Adds the given columns to this Relation and returns the same relation.- Returns:
- This Relation
-
setName
Sets the name of this Relation and returns the same relation.- Returns:
- This Relation
-
isEmpty
public boolean isEmpty()Returns true if this relation has zero rows and false otherwise. Rows of missing values are counted. -
shape
Returns a string that tells how many rows and columns this relation has -
removeColumns
Removes the columns at the given 0-based indices from this Relation and returns the same relation.- Returns:
- This Relation
-
removeColumns
Removes the given columns from this Relation and returns the same relation.- Returns:
- This Relation
-
removeColumns
Removes the columns with the given namesfrom this Relation and returns the same relation.- Returns:
- This Relation
-
columnsOfType
Returns a list containing all the columns of the given type in this Relation -
first
Returns a new table containing the first n rows in this Relation -
columnIndex
Returns the index of the column with the given columnName -
column
Returns the column with the given columnName, ignoring case -
column
Returns the column at columnIndex (0-based)- Parameters:
columnIndex
- an integer at least 0 and less than number of columns in the relation- Returns:
- the column at the given index
-
columnCount
public abstract int columnCount()Returns the number of columns in the relation -
rowCount
public abstract int rowCount()Returns the number of rows in the relation -
columns
Returns a list of all the columns in the relation -
columns
Returns the columns whose names are given in the input array -
columns
Returns the columns whose indices are given in the input array -
columnIndex
Returns the index of the given column -
get
Returns the value at the given row and column indexes- Parameters:
r
- the row index, 0 basedc
- the column index, 0 based
-
name
Returns the name of this relation -
clear
public abstract void clear()Clears all the dat in the relation, leaving the structure intact -
columnNames
Returns a list containing the names of all the columns in this relation -
columnTypes
Deprecated.for API name consistency. UsetypeArray()
instead.Returns an array of the column types of all columns in the relation, including duplicates as appropriate, and maintaining order -
typeArray
Returns an array of the column types of all columns in the relation, including duplicates as appropriate, and maintaining order -
types
Returns a List of the column types of all columns in the relation, including duplicates as appropriate, and maintaining order -
colWidths
public int[] colWidths()Returns an array of column widths for printing tables -
toString
Returns a String containing a 'pretty-printed' representation of this table containing at most 20 rows. The 20 rows are the first and last ten in this table. -
printAll
Returns a 'pretty-printed' string representation of this entire relation. -
print
Returns a 'pretty-printed' string representation of at most rowLimit rows from this relation. -
print
Returns a String containing a 'pretty-printed' representation of this table containing at most 20 rows. The 20 rows are the first and last ten in this table. -
structure
Returns the structure of the this relation as a 3-column Table, consisting of Index (an IntColumn), Column Name (a StringColumn), and Column Type (a StringColumn) -
summary
Returns a table containing summary statistics for the columns in this Relation -
booleanColumn
Returns the DoubleColumn at the given 0-based index if present. A ClassCastException is the column is of a different type. -
booleanColumn
Returns a BooleanColumn with the given name if it is present in this Relation. If the column is of a different type, a ClassCastException is thrown -
numberColumn
Returns the NumberColumn at the given index. If the index points to a String or a boolean column, a new NumberColumn is created and returned TODO(lwhite):Consider separating the indexed access and the column type mods, which must be for ML functions (in smile or elsewhere)- Parameters:
columnIndex
- The 0-based index of a column in the table- Returns:
- A number column
- Throws:
ClassCastException
- if the cast to NumberColumn fails
-
numberColumn
Returns a NumericColumn with the given name if it is present in this Relation. If the column is not Numeric, a ClassCastException is thrown -
doubleColumn
Returns a DoubleColumn with the given name if it is present in this Relation. If the column is not of type DOUBLE, a ClassCastException is thrown -
doubleColumn
Returns the DoubleColumn at the given 0-based index if present. A ClassCastException is the column is of a different type. -
stringColumns
Returns all the StringColumns in this Relation as an Array -
numberColumns
Returns all the NumericColumns in this Relation as an Array -
numericColumns
Returns all the NumericColumns in the relation -
numericColumns
Returns all the NumericColumns in the relation -
numericColumns
Returns all the NumericColumns in the relation -
booleanColumns
Returns all BooleanColumns in this Relation as an Array -
dateColumns
Returns all DateColumns in this Relation as an Array -
dateTimeColumns
Returns all DateTimeColumns in this Relation as an Array -
instantColumns
Returns all InstantColumns in this Relation as an Array -
timeColumns
Returns all TimeColumns in this Relation as an Array -
categoricalColumn
Returns a CategoricalColumn with the given name if it is present in this Relation. If the column is not Categorical, a ClassCastException is thrown -
categoricalColumn
Returns the CategoricalColumn at the given 0-based index if present. A ClassCastException is thrown otherwise -
categoricalColumns
Returns the columns whose names are given in the input array -
nCol
Returns the column with the given name cast to a NumberColumn. If the column is not Numeric, a ClassCastException is thrownShorthand for numberColumn()
-
nCol
Returns the column with the given name cast to a NumberColumnShorthand for numberColumn()
-
intColumn
Returns an IntColumn with the given name if it is present in this Relation. If the column has a different type, a ClassCastException is thrown. -
intColumn
Returns the IntColumn at the given 0-based index if present. A ClassCastException is the column is of a different type. -
shortColumn
Returns a ShortColumn with the given name if it is present in this Relation. If the column has a different type, a ClassCastException is thrown. -
shortColumn
Returns the ShortColumn at the given 0-based index if present. A ClassCastException is the column is of a different type. -
longColumn
Returns a LongColumn with the given name if it is present in this Relation. If the column has a different type, a ClassCastException is thrown. -
longColumn
Returns the LongColumn at the given 0-based index if present. A ClassCastException is the column is of a different type. -
floatColumn
Returns a FloatColumn with the given name if it is present in this Relation. If the column has a different type, a ClassCastException is thrown. -
floatColumn
Returns the FloatColumn at the given 0-based index if present. A ClassCastException is the column is of a different type. -
dateColumn
Returns the DateColumn at the given 0-based index if present. A ClassCastException is the column is of a different type. -
dateColumn
Returns a DateColumn with the given name if it is present in this Relation. If the column has a different type, a ClassCastException is thrown. -
timeColumn
Returns a TimeColumn with the given name if it is present in this Relation. If the column has a different type, a ClassCastException is thrown. -
timeColumn
Returns the TimeColumn at the given 0-based index if present. A ClassCastException is the column is of a different type. -
stringColumn
Returns a StringColumn with the given name if it is present in this Relation. If the column has a different type, a ClassCastException is thrown. -
stringColumn
Returns the StringColumn at the given 0-based index if present. A ClassCastException is the column is of a different type. -
textColumn
Returns a TextColumn with the given name if it is present in this Relation. If the column has a different type, a ClassCastException is thrown. -
textColumn
Returns the TextColumn at the given 0-based index if present. A ClassCastException is the column is of a different type. -
dateTimeColumn
Returns the DateTimeColumn at the given 0-based index if present. A ClassCastException is the column is of a different type. -
dateTimeColumn
Returns a DateTimeColumn with the given name if it is present in this Relation. If the column has a different type, a ClassCastException is thrown. -
instantColumn
Returns the InstantColumn at the given 0-based index if present. A ClassCastException is the column is of a different type. -
instantColumn
Returns an InstantColumn with the given name if it is present in this Relation. If the column has a different type, a ClassCastException is thrown. -
as
Returns anTableConverter
that can convert this Relation to a two-dimensional matrix of primitive numeric values -
smile
Returns anSmileConverter
that can convert this table to a format suitable for use with the Smile machine learning library. -
getUnformatted
Returns a string representation of the value at the given row and column indexes- Parameters:
r
- the row index, 0 basedc
- the column index, 0 based
-
getString
Returns a string representation of the value at the given row and column indexes- Parameters:
r
- the row index, 0 basedcolumnName
- the name of the column to be returned// TODO: performance would be enhanced if columns could be referenced via a hashTable
-
getString
Returns a string representation of the value at the given row and column indexes- Parameters:
r
- the row index, 0 basedcolumnIndex
- the index of the column to be returned// TODO: performance would be enhanced if columns could be referenced via a hashTable
-
containsColumn
Returns true if the given column is in this Relation -
containsColumn
Returns true if a column with the given name is in this Relation
-