public class Table extends Relation implements Iterable<Row>
Tables are the main data-type and primary focus of Tablesaw.
Modifier and Type | Class and Description |
---|---|
static class |
Table.RowPair
Deprecated.
|
Modifier and Type | Field and Description |
---|---|
static ReaderRegistry |
defaultReaderRegistry |
static WriterRegistry |
defaultWriterRegistry |
Modifier | Constructor and Description |
---|---|
protected |
Table(Column<?>... columns)
Returns a new Table initialized with the given columns
|
protected |
Table(String name,
Column<?>... columns)
Returns a new Table initialized with the given names and columns
|
Modifier and Type | Method and Description |
---|---|
Table |
addColumns(Column<?>... cols)
Adds the given column to this table
|
void |
addRow(int rowIndex,
Table sourceTable)
Adds a single row to this table from sourceTable, copying every column in sourceTable
|
void |
addRow(Row row) |
Table |
append(Table tableToAppend) |
Row |
appendRow()
Appends an empty row and returns a Row object indexed to the newly added row so values can be
set.
|
List<CategoricalColumn<?>> |
categoricalColumns(String... columnNames)
Returns only the columns whose names are given in the input array
|
void |
clear()
Clears all the data from this table
|
Column<?> |
column(int columnIndex)
Returns the column at the given index in the column list
|
Column<?>[] |
columnArray() |
int |
columnCount()
Returns the number of columns in the table
|
int |
columnIndex(Column<?> column)
Returns the index of the given column (its position in the list of columns)
|
int |
columnIndex(String columnName)
Returns the index of the column with the given name
|
List<String> |
columnNames()
Returns a List of the names of all the columns in this table
|
List<Column<?>> |
columns()
Returns the list of columns
|
Table |
concat(Table tableToConcatenate)
Add all the columns of tableToConcatenate to this table Note: The columns in the result must
have unique names, when compared case insensitive Note: Both tables must have the same number
of rows
|
Table |
copy()
Returns a table with the same columns as this table
|
Table |
countBy(CategoricalColumn<?> groupingColumn)
Returns a table containing two columns, the grouping column, and a column named "Count" that
contains the counts for each grouping column value
|
Table |
countBy(String categoricalColumnName)
Returns a table containing two columns, the grouping column, and a column named "Count" that
contains the counts for each grouping column value
|
static Table |
create()
Returns a new, empty table (without rows or columns)
|
static Table |
create(Column<?>... columns)
Returns a new table with the given columns
|
static Table |
create(String tableName)
Returns a new, empty table (without rows or columns) with the given name
|
static Table |
create(String name,
Column<?>... columns)
Returns a new table with the given columns and given name
|
boolean |
detect(Predicate<Row> predicate)
Deprecated.
use
stream().anyMatch |
void |
doWithRowPairs(Consumer<Table.RowPair> pairConsumer)
Deprecated.
use stream(2).forEach(rowConsumer)
|
void |
doWithRows(Consumer<Row> doable)
Deprecated.
use
stream().forEach |
void |
doWithRows(tech.tablesaw.api.Table.Pairs pairs)
Deprecated.
use stream(2).forEach(rowConsumer)
|
Table |
dropDuplicateRows()
Returns the unique records in this table Note: Uses a lot of memory for a sort
|
Table |
dropRange(int rowCount)
Drops the first rowCount rows if rowCount positive.
|
Table |
dropRange(int rowStart,
int rowEnd) |
Table |
dropRows(int... rowNumbers) |
Table |
dropRowsWithMissingValues()
Returns only those records in this table that have no columns with missing values
|
Table |
dropWhere(Function<Table,Selection> selection) |
Table |
dropWhere(Selection selection) |
Table |
emptyCopy()
Returns a table with the same columns as this table, but no data
|
Table |
emptyCopy(int rowSize)
Returns a table with the same columns as this table, but no data, initialized to the given row
size
|
Table |
first(int nRows)
Returns a new table containing the first
nrows of data in this table |
Table |
inRange(int rowCount)
Retains the first rowCount rows if rowCount positive.
|
Table |
inRange(int rowStart,
int rowEnd) |
Table |
insertColumn(int index,
Column<?> column)
Adds the given column to this table at the given position in the column list
|
Iterator<Row> |
iterator() |
DataFrameJoiner |
joinOn(String... columnNames)
Returns a new DataFrameJoiner initialized with multiple
columnNames |
Table |
last(int nRows)
Returns a new table containing the last
nrows of data in this table |
Table |
missingValueCounts() |
String |
name()
Returns the name of the table
|
Table |
pivot(CategoricalColumn<?> column1,
CategoricalColumn<?> column2,
NumericColumn<?> column3,
AggregateFunction<?,?> aggregateFunction)
Returns a pivot on this table, where: The first column contains unique values from the index
column1 There are n additional columns, one for each unique value in column2 The values in each
of the cells in these new columns are the result of applying the given AggregateFunction to the
data in column3, grouped by the values of column1 and column2
|
Table |
pivot(String column1Name,
String column2Name,
String column3Name,
AggregateFunction<?,?> aggregateFunction)
Returns a pivot on this table, where: The first column contains unique values from the index
column1 There are n additional columns, one for each unique value in column2 The values in each
of the cells in these new columns are the result of applying the given AggregateFunction to the
data in column3, grouped by the values of column1 and column2
|
static DataFrameReader |
read() |
Table |
removeColumns(Column<?>... columns)
Removes the given columns
|
Table |
removeColumnsWithMissingValues()
Removes the given columns with missing values
|
Table |
replaceColumn(Column<?> newColumn)
Replaces an existing column having the same name of the given column with the given column
|
Table |
replaceColumn(int colIndex,
Column<?> newColumn)
Replaces an existing column (by index) in this table with the given new column
|
Table |
replaceColumn(String columnName,
Column<?> newColumn)
Replaces an existing column (by name) in this table with the given new column
|
Table |
retainColumns(Column<?>... columns)
Removes all columns except for those given in the argument from this table
|
Table |
retainColumns(String... columnNames)
Removes all columns except for those given in the argument from this table
|
Iterator<Row[]> |
rollingIterator(int n)
Iterates over rolling sets of rows.
|
Stream<Row[]> |
rollingStream(int n)
Streams over rolling sets of rows.
|
void |
rollWithRows(Consumer<Row[]> rowConsumer,
int n)
Deprecated.
use stream(n).forEach(rowConsumer)
|
Row |
row(int rowIndex) |
int |
rowCount()
Returns the number of rows in the table
|
Table |
rows(int... rowNumbers) |
Table |
sampleN(int nRows)
Returns a table consisting of randomly selected records from this table
|
Table[] |
sampleSplit(double table1Proportion)
Splits the table into two, randomly assigning records to each according to the proportion given
in trainingProportion
|
Table |
sampleX(double proportion)
Returns a table consisting of randomly selected records from this table.
|
Table |
select(Column<?>... columns) |
Table |
select(String... columnNames) |
Table |
setName(String name)
Sets the name of the table
|
Table |
sortAscendingOn(String... columnNames)
Returns a copy of this table sorted in the order of the given column names, in ascending order
|
Table |
sortDescendingOn(String... columnNames)
Returns a copy of this table sorted on the given column names, applied in order, descending
TODO: Provide equivalent methods naming columns by index
|
Table |
sortOn(Comparator<Row> rowComparator)
Returns a copy of this table sorted using the given comparator
|
Table |
sortOn(int... columnIndexes)
Sorts this table into a new table on the columns indexed
|
Table |
sortOn(Sort key)
Returns a copy of this table sorted using the given sort key.
|
Table |
sortOn(String... columnNames)
Returns a copy of this table sorted on the given column names, applied in order,
|
TableSliceGroup |
splitOn(CategoricalColumn<?>... columns)
Returns a non-overlapping and exhaustive collection of "slices" over this table.
|
TableSliceGroup |
splitOn(String... columns)
Returns a non-overlapping and exhaustive collection of "slices" over this table.
|
Iterator<Row[]> |
steppingIterator(int n)
Streams over stepped sets of rows.
|
Stream<Row[]> |
steppingStream(int n)
Streams over stepped sets of rows.
|
void |
stepWithRows(Consumer<Row[]> rowConsumer,
int n)
Deprecated.
use steppingStream(n).forEach(rowConsumer)
|
Table[] |
stratifiedSampleSplit(CategoricalColumn<?> column,
double table1Proportion)
Splits the table into two stratified samples, this uses the specified column to divide the
table into groups, randomly assigning records to each according to the proportion given in
trainingProportion.
|
Stream<Row> |
stream() |
Table |
structure() |
Summarizer |
summarize(Column<?> numberColumn,
AggregateFunction<?,?>... function) |
Summarizer |
summarize(Column<?> column1,
Column<?> column2,
AggregateFunction<?,?>... function) |
Summarizer |
summarize(Column<?> column1,
Column<?> column2,
Column<?> column3,
AggregateFunction<?,?>... function) |
Summarizer |
summarize(Column<?> column1,
Column<?> column2,
Column<?> column3,
Column<?> column4,
AggregateFunction<?,?>... function) |
Summarizer |
summarize(List<String> columnNames,
AggregateFunction<?,?>... functions) |
Summarizer |
summarize(String columName,
AggregateFunction<?,?>... functions) |
Summarizer |
summarize(String numericColumn1Name,
String numericColumn2Name,
AggregateFunction<?,?>... functions) |
Summarizer |
summarize(String col1Name,
String col2Name,
String col3Name,
AggregateFunction<?,?>... functions) |
Summarizer |
summarize(String col1Name,
String col2Name,
String col3Name,
String col4Name,
AggregateFunction<?,?>... functions) |
Table |
where(Function<Table,Selection> selection) |
Table |
where(Selection selection) |
DataFrameWriter |
write() |
Table |
xTabColumnPercents(String column1Name,
String column2Name) |
Table |
xTabCounts(String column1Name)
Returns a table with two columns, the first contains a value each unique value in the argument,
and the second contains the number of observations of each value
|
Table |
xTabCounts(String column1Name,
String column2Name)
Returns a table with n by m + 1 cells.
|
Table |
xTabPercents(String column1Name)
Returns a table with two columns, the first contains a value each unique value in the argument,
and the second contains the proportion of observations having that value
|
Table |
xTabRowPercents(String column1Name,
String column2Name) |
Table |
xTabTablePercents(String column1Name,
String column2Name)
Returns a table with n by m + 1 cells.
|
as, booleanColumn, booleanColumn, booleanColumns, categoricalColumn, categoricalColumn, column, columns, columns, columnsOfType, columnTypes, colWidths, containsColumn, dateColumn, dateColumn, dateColumns, dateTimeColumn, dateTimeColumn, dateTimeColumns, doubleColumn, doubleColumn, floatColumn, floatColumn, get, getString, getString, getUnformatted, instantColumn, instantColumn, instantColumns, intColumn, intColumn, isEmpty, longColumn, longColumn, nCol, nCol, numberColumn, numberColumn, numberColumns, numericColumns, numericColumns, numericColumns, print, print, printAll, removeColumns, removeColumns, shape, shortColumn, shortColumn, smile, stringColumn, stringColumn, stringColumns, summary, textColumn, textColumn, timeColumn, timeColumn, timeColumns, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
forEach, spliterator
public static final ReaderRegistry defaultReaderRegistry
public static final WriterRegistry defaultWriterRegistry
protected Table(Column<?>... columns)
columns
- One or more columns, all of which must have either the same length or size 0public static Table create()
public static Table create(String tableName)
public static Table create(Column<?>... columns)
columns
- one or more columns, all of the same @code{column.size()}public static Table create(String name, Column<?>... columns)
name
- the name for this tablecolumns
- one or more columns, all of the same @code{column.size()}public static DataFrameReader read()
public DataFrameWriter write()
public Table addColumns(Column<?>... cols)
addColumns
in class Relation
public Table insertColumn(int index, Column<?> column)
index
- Zero-based index into the column listcolumn
- Column to be addedpublic Table replaceColumn(int colIndex, Column<?> newColumn)
colIndex
- Zero-based index of the column to be replacednewColumn
- Column to be addedpublic Table replaceColumn(String columnName, Column<?> newColumn)
columnName
- String name of the column to be replacednewColumn
- Column to be addedpublic Table replaceColumn(Column<?> newColumn)
newColumn
- Column to be addedpublic Column<?> column(int columnIndex)
public int columnCount()
columnCount
in class Relation
public int rowCount()
public Column<?>[] columnArray()
public List<CategoricalColumn<?>> categoricalColumns(String... columnNames)
categoricalColumns
in class Relation
public int columnIndex(String columnName)
columnIndex
in class Relation
IllegalArgumentException
- if the input string is not the name of any column in the tablepublic int columnIndex(Column<?> column)
columnIndex
in class Relation
IllegalArgumentException
- if the column is not present in this tablepublic List<String> columnNames()
columnNames
in class Relation
public Table copy()
public Table emptyCopy()
public Table emptyCopy(int rowSize)
public Table[] sampleSplit(double table1Proportion)
table1Proportion
- The proportion to go in the first tablepublic Table[] stratifiedSampleSplit(CategoricalColumn<?> column, double table1Proportion)
column
- the column to be used for the stratified samplingtable1Proportion
- The proportion to go in the first tablepublic Table sampleX(double proportion)
proportion
- The proportion to go in the samplepublic Table sampleN(int nRows)
nRows
- The number of rows to go in the samplepublic Table first(int nRows)
nrows
of data in this tablepublic Table last(int nRows)
nrows
of data in this tablepublic Table sortOn(int... columnIndexes)
if index is negative then sort that column in descending order otherwise sort ascending
public Table sortOn(String... columnNames)
if column name starts with - then sort that column descending otherwise sort ascending
public Table sortAscendingOn(String... columnNames)
public Table sortDescendingOn(String... columnNames)
public Table sortOn(Sort key)
key
- to sort on.public Table sortOn(Comparator<Row> rowComparator)
public void addRow(int rowIndex, Table sourceTable)
rowIndex
- The row in sourceTable to add to this tablesourceTable
- A table with the same column structure as this tablepublic void addRow(Row row)
public Row row(int rowIndex)
public Table rows(int... rowNumbers)
public Table dropRows(int... rowNumbers)
public Table inRange(int rowCount)
public Table inRange(int rowStart, int rowEnd)
public Table dropRange(int rowCount)
public Table dropRange(int rowStart, int rowEnd)
public Table pivot(CategoricalColumn<?> column1, CategoricalColumn<?> column2, NumericColumn<?> column3, AggregateFunction<?,?> aggregateFunction)
public Table pivot(String column1Name, String column2Name, String column3Name, AggregateFunction<?,?> aggregateFunction)
public TableSliceGroup splitOn(String... columns)
This method is intended for advanced or unusual operations on the subtables. If you want to calculate summary statistics for each subtable, the summarize methods (e.g)
table.summarize(myColumn, mean, median).by(columns)
are preferred
public TableSliceGroup splitOn(CategoricalColumn<?>... columns)
This method is intended for advanced or unusual operations on the subtables. If you want to calculate summary statistics for each subtable, the summarize methods (e.g)
table.summarize(myColumn, mean, median).by(columns)
are preferred
public Table dropDuplicateRows()
public Table dropRowsWithMissingValues()
public Table removeColumns(Column<?>... columns)
removeColumns
in class Relation
public Table removeColumnsWithMissingValues()
public Table retainColumns(Column<?>... columns)
public Table retainColumns(String... columnNames)
public Row appendRow()
Intended usage:
for (int i = 0; ...) { Row row = table.appendRow(); row.setString("name", "Bob"); row.setFloat("IQ", 123.4f); ...etc. }
public Table concat(Table tableToConcatenate)
tableToConcatenate
- The table containing the columns to be addedpublic Summarizer summarize(String columName, AggregateFunction<?,?>... functions)
public Summarizer summarize(List<String> columnNames, AggregateFunction<?,?>... functions)
public Summarizer summarize(String numericColumn1Name, String numericColumn2Name, AggregateFunction<?,?>... functions)
public Summarizer summarize(String col1Name, String col2Name, String col3Name, AggregateFunction<?,?>... functions)
public Summarizer summarize(String col1Name, String col2Name, String col3Name, String col4Name, AggregateFunction<?,?>... functions)
public Summarizer summarize(Column<?> numberColumn, AggregateFunction<?,?>... function)
public Summarizer summarize(Column<?> column1, Column<?> column2, AggregateFunction<?,?>... function)
public Summarizer summarize(Column<?> column1, Column<?> column2, Column<?> column3, AggregateFunction<?,?>... function)
public Summarizer summarize(Column<?> column1, Column<?> column2, Column<?> column3, Column<?> column4, AggregateFunction<?,?>... function)
public Table xTabCounts(String column1Name, String column2Name)
public Table xTabTablePercents(String column1Name, String column2Name)
public Table xTabPercents(String column1Name)
public Table xTabCounts(String column1Name)
public Table countBy(CategoricalColumn<?> groupingColumn)
public Table countBy(String categoricalColumnName)
categoricalColumnName
- The name of a CategoricalColumn in this tableClassCastException
- if the categoricalColumnName parameter is the name of a column that
does not * implement categoricalpublic DataFrameJoiner joinOn(String... columnNames)
columnNames
columnNames
- Name of the columns to join on.public Table missingValueCounts()
public Iterator<Row[]> rollingIterator(int n)
n
- the number of rows to return for each iterationpublic Iterator<Row[]> steppingIterator(int n)
n
- the number of rows to return for each iterationpublic Stream<Row[]> steppingStream(int n)
n
- the number of rows to return for each iterationpublic Stream<Row[]> rollingStream(int n)
n
- the number of rows to return for each iteration@Deprecated public void doWithRows(Consumer<Row> doable)
stream().forEach
doable
to every row in the table@Deprecated public boolean detect(Predicate<Row> predicate)
stream().anyMatch
@Deprecated public void stepWithRows(Consumer<Row[]> rowConsumer, int n)
@Deprecated public void doWithRows(tech.tablesaw.api.Table.Pairs pairs)
@Deprecated public void doWithRowPairs(Consumer<Table.RowPair> pairConsumer)
@Deprecated public void rollWithRows(Consumer<Row[]> rowConsumer, int n)
Copyright © 2020. All rights reserved.