Package tech.tablesaw.table
Class Relation
- java.lang.Object
-
- tech.tablesaw.table.Relation
-
-
Constructor Summary
Constructors Constructor Description Relation()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract Relation
addColumns(Column<?>... cols)
Adds the given columns to this Relation and returns the same relation.TableConverter
as()
Returns anTableConverter
that can convert this Relation to a two-dimensional matrix of primitive numeric valuesBooleanColumn
booleanColumn(int columnIndex)
Returns the DoubleColumn at the given 0-based index if present.BooleanColumn
booleanColumn(String columnName)
Returns a BooleanColumn with the given name if it is present in this Relation.BooleanColumn[]
booleanColumns()
Returns all BooleanColumns in this Relation as an ArrayCategoricalColumn<?>
categoricalColumn(int columnNumber)
Returns the CategoricalColumn at the given 0-based index if present.CategoricalColumn<?>
categoricalColumn(String columnName)
Returns a CategoricalColumn with the given name if it is present in this Relation.List<CategoricalColumn<?>>
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<?>
column(String columnName)
Returns the column with the given columnName, ignoring caseabstract int
columnCount()
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 columnabstract List<String>
columnNames()
Returns a list containing the names of all the columns in this relationabstract List<Column<?>>
columns()
Returns a list of all the columns in the relationList<Column<?>>
columns(int... columnIndices)
Returns the columns whose indices are given in the input arrayList<Column<?>>
columns(String... columnName)
Returns the columns whose names are given in the input arrayList<Column<?>>
columnsOfType(ColumnType type)
Returns a list containing all the columns of the given type in this Relationint[]
colWidths()
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
dateColumn(int columnIndex)
Returns the DateColumn at the given 0-based index if present.DateColumn
dateColumn(String columnName)
Returns a DateColumn with the given name if it is present in this Relation.DateColumn[]
dateColumns()
Returns all DateColumns in this Relation as an ArrayDateTimeColumn
dateTimeColumn(int columnIndex)
Returns the DateTimeColumn at the given 0-based index if present.DateTimeColumn
dateTimeColumn(String columnName)
Returns a DateTimeColumn with the given name if it is present in this Relation.DateTimeColumn[]
dateTimeColumns()
Returns all DateTimeColumns in this Relation as an ArrayDoubleColumn
doubleColumn(int columnIndex)
Returns the DoubleColumn at the given 0-based index if present.DoubleColumn
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
floatColumn(int columnIndex)
Returns the FloatColumn at the given 0-based index if present.FloatColumn
floatColumn(String columnName)
Returns a FloatColumn with the given name if it is present in this Relation.Object
get(int r, int c)
Returns the value at the given row and column indexesString
getString(int r, int columnIndex)
Returns a string representation of the value at the given row and column indexesString
getString(int r, String columnName)
Returns a string representation of the value at the given row and column indexesString
getUnformatted(int r, int c)
Returns a string representation of the value at the given row and column indexesInstantColumn
instantColumn(int columnIndex)
Returns the InstantColumn at the given 0-based index if present.InstantColumn
instantColumn(String columnName)
Returns an InstantColumn with the given name if it is present in this Relation.InstantColumn[]
instantColumns()
Returns all InstantColumns in this Relation as an ArrayIntColumn
intColumn(int columnIndex)
Returns the IntColumn at the given 0-based index if present.IntColumn
intColumn(String columnName)
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
longColumn(int columnIndex)
Returns the LongColumn at the given 0-based index if present.LongColumn
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 relationNumericColumn<?>
nCol(int columnIndex)
Returns the column with the given name cast to a NumberColumnNumericColumn<?>
nCol(String columnName)
Returns the column with the given name cast to a NumberColumn.NumericColumn<?>
numberColumn(int columnIndex)
Returns the NumberColumn at the given index.NumericColumn<?>
numberColumn(String columnName)
Returns a NumericColumn with the given name if it is present in this Relation.NumericColumn<?>[]
numberColumns()
Returns all the NumericColumns in this Relation as an ArrayList<NumericColumn<?>>
numericColumns()
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 relationString
print()
Returns a String containing a 'pretty-printed' representation of this table containing at most 20 rows.String
print(int rowLimit)
Returns a 'pretty-printed' string representation of at most rowLimit rows from this relation.String
printAll()
Returns a 'pretty-printed' string representation of this entire relation.Relation
removeColumns(int... columnIndexes)
Removes the columns at the given 0-based indices from this Relation and returns the same relation.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
setName(String name)
Sets the name of this Relation and returns the same relation.String
shape()
Returns a string that tells how many rows and columns this relation hasShortColumn
shortColumn(int columnIndex)
Returns the ShortColumn at the given 0-based index if present.ShortColumn
shortColumn(String columnName)
Returns a ShortColumn with the given name if it is present in this Relation.SmileConverter
smile()
Returns anSmileConverter
that can convert this table to a format suitable for use with the Smile machine learning library.StringColumn
stringColumn(int columnIndex)
Returns the StringColumn at the given 0-based index if present.StringColumn
stringColumn(String columnName)
Returns a StringColumn with the given name if it is present in this Relation.StringColumn[]
stringColumns()
Returns all the StringColumns in this Relation as an ArrayTable
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)Table
summary()
Returns a table containing summary statistics for the columns in this RelationTimeColumn
timeColumn(int columnIndex)
Returns the TimeColumn at the given 0-based index if present.TimeColumn
timeColumn(String columnName)
Returns a TimeColumn with the given name if it is present in this Relation.TimeColumn[]
timeColumns()
Returns all TimeColumns in this Relation as an ArrayString
toString()
Returns a String containing a 'pretty-printed' representation of this table containing at most 20 rows.ColumnType[]
typeArray()
Returns an array of the column types of all columns in the relation, including duplicates as appropriate, and maintaining orderList<ColumnType>
types()
Returns a List of the column types of all columns in the relation, including duplicates as appropriate, and maintaining order-
Methods 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
-
-
-
-
Method Detail
-
addColumns
public abstract Relation addColumns(Column<?>... cols)
Adds the given columns to this Relation and returns the same relation.- Returns:
- This Relation
-
setName
public abstract Relation setName(String name)
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
public String shape()
Returns a string that tells how many rows and columns this relation has
-
removeColumns
public Relation removeColumns(int... columnIndexes)
Removes the columns at the given 0-based indices from this Relation and returns the same relation.- Returns:
- This Relation
-
removeColumns
public abstract Relation removeColumns(Column<?>... columns)
Removes the given columns from this Relation and returns the same relation.- Returns:
- This Relation
-
removeColumns
public Relation removeColumns(String... columnName)
Removes the columns with the given namesfrom this Relation and returns the same relation.- Returns:
- This Relation
-
columnsOfType
public List<Column<?>> columnsOfType(ColumnType type)
Returns a list containing all the columns of the given type in this Relation
-
first
public abstract Table first(int nRows)
Returns a new table containing the first n rows in this Relation
-
columnIndex
public int columnIndex(String columnName)
Returns the index of the column with the given columnName
-
column
public Column<?> column(String columnName)
Returns the column with the given columnName, ignoring case
-
column
public abstract Column<?> column(int columnIndex)
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
public List<Column<?>> columns(String... columnName)
Returns the columns whose names are given in the input array
-
columns
public List<Column<?>> columns(int... columnIndices)
Returns the columns whose indices are given in the input array
-
columnIndex
public abstract int columnIndex(Column<?> col)
Returns the index of the given column
-
get
public Object get(int r, int c)
Returns the value at the given row and column indexes- Parameters:
r
- the row index, 0 basedc
- the column index, 0 based
-
name
public abstract String name()
Returns the name of this relation
-
clear
public abstract void clear()
Clears all the dat in the relation, leaving the structure intact
-
columnNames
public abstract List<String> columnNames()
Returns a list containing the names of all the columns in this relation
-
typeArray
public ColumnType[] typeArray()
Returns an array of the column types of all columns in the relation, including duplicates as appropriate, and maintaining order
-
types
public List<ColumnType> 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
public String 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
public String printAll()
Returns a 'pretty-printed' string representation of this entire relation.
-
print
public String print(int rowLimit)
Returns a 'pretty-printed' string representation of at most rowLimit rows from this relation.
-
print
public String 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
public 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
public Table summary()
Returns a table containing summary statistics for the columns in this Relation
-
booleanColumn
public BooleanColumn booleanColumn(int columnIndex)
Returns the DoubleColumn at the given 0-based index if present. A ClassCastException is the column is of a different type.
-
booleanColumn
public BooleanColumn booleanColumn(String columnName)
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
public NumericColumn<?> numberColumn(int columnIndex)
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
public NumericColumn<?> numberColumn(String columnName)
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
public DoubleColumn doubleColumn(String columnName)
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
public DoubleColumn doubleColumn(int columnIndex)
Returns the DoubleColumn at the given 0-based index if present. A ClassCastException is the column is of a different type.
-
stringColumns
public StringColumn[] stringColumns()
Returns all the StringColumns in this Relation as an Array
-
numberColumns
public NumericColumn<?>[] numberColumns()
Returns all the NumericColumns in this Relation as an Array
-
numericColumns
public List<NumericColumn<?>> numericColumns()
Returns all the NumericColumns in the relation
-
numericColumns
public List<NumericColumn<?>> numericColumns(int... columnIndices)
Returns all the NumericColumns in the relation
-
numericColumns
public List<NumericColumn<?>> numericColumns(String... columnNames)
Returns all the NumericColumns in the relation
-
booleanColumns
public BooleanColumn[] booleanColumns()
Returns all BooleanColumns in this Relation as an Array
-
dateColumns
public DateColumn[] dateColumns()
Returns all DateColumns in this Relation as an Array
-
dateTimeColumns
public DateTimeColumn[] dateTimeColumns()
Returns all DateTimeColumns in this Relation as an Array
-
instantColumns
public InstantColumn[] instantColumns()
Returns all InstantColumns in this Relation as an Array
-
timeColumns
public TimeColumn[] timeColumns()
Returns all TimeColumns in this Relation as an Array
-
categoricalColumn
public CategoricalColumn<?> categoricalColumn(String columnName)
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
public CategoricalColumn<?> categoricalColumn(int columnNumber)
Returns the CategoricalColumn at the given 0-based index if present. A ClassCastException is thrown otherwise
-
categoricalColumns
public List<CategoricalColumn<?>> categoricalColumns(String... columnName)
Returns the columns whose names are given in the input array
-
nCol
public NumericColumn<?> nCol(String columnName)
Returns the column with the given name cast to a NumberColumn. If the column is not Numeric, a ClassCastException is thrownShorthand for numberColumn()
-
nCol
public NumericColumn<?> nCol(int columnIndex)
Returns the column with the given name cast to a NumberColumnShorthand for numberColumn()
-
intColumn
public IntColumn intColumn(String columnName)
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
public IntColumn intColumn(int columnIndex)
Returns the IntColumn at the given 0-based index if present. A ClassCastException is the column is of a different type.
-
shortColumn
public ShortColumn shortColumn(String columnName)
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
public ShortColumn shortColumn(int columnIndex)
Returns the ShortColumn at the given 0-based index if present. A ClassCastException is the column is of a different type.
-
longColumn
public LongColumn longColumn(String columnName)
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
public LongColumn longColumn(int columnIndex)
Returns the LongColumn at the given 0-based index if present. A ClassCastException is the column is of a different type.
-
floatColumn
public FloatColumn floatColumn(String columnName)
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
public FloatColumn floatColumn(int columnIndex)
Returns the FloatColumn at the given 0-based index if present. A ClassCastException is the column is of a different type.
-
dateColumn
public DateColumn dateColumn(int columnIndex)
Returns the DateColumn at the given 0-based index if present. A ClassCastException is the column is of a different type.
-
dateColumn
public DateColumn dateColumn(String columnName)
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
public TimeColumn timeColumn(String columnName)
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
public TimeColumn timeColumn(int columnIndex)
Returns the TimeColumn at the given 0-based index if present. A ClassCastException is the column is of a different type.
-
stringColumn
public StringColumn stringColumn(String columnName)
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
public StringColumn stringColumn(int columnIndex)
Returns the StringColumn at the given 0-based index if present. A ClassCastException is the column is of a different type.
-
dateTimeColumn
public DateTimeColumn dateTimeColumn(int columnIndex)
Returns the DateTimeColumn at the given 0-based index if present. A ClassCastException is the column is of a different type.
-
dateTimeColumn
public DateTimeColumn dateTimeColumn(String columnName)
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
public InstantColumn instantColumn(int columnIndex)
Returns the InstantColumn at the given 0-based index if present. A ClassCastException is the column is of a different type.
-
instantColumn
public InstantColumn instantColumn(String columnName)
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
public TableConverter as()
Returns anTableConverter
that can convert this Relation to a two-dimensional matrix of primitive numeric values
-
smile
public SmileConverter smile()
Returns anSmileConverter
that can convert this table to a format suitable for use with the Smile machine learning library.
-
getUnformatted
public String getUnformatted(int r, int c)
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
public String getString(int r, String columnName)
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
public String getString(int r, int columnIndex)
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
public boolean containsColumn(Column<?> column)
Returns true if the given column is in this Relation
-
containsColumn
public boolean containsColumn(String columnName)
Returns true if a column with the given name is in this Relation
-
-