public class Table extends java.lang.Object implements Relation, it.unimi.dsi.fastutil.ints.IntIterable
Tables are the main data-type and primary focus of Tablesaw.
Modifier | Constructor and Description |
---|---|
protected |
Table(java.lang.String name,
Column... columns)
Returns a new Table initialized with the given names and columns
|
Modifier and Type | Method and Description |
---|---|
void |
addColumn(Column... cols)
Adds the given column to this table
|
void |
addColumn(int index,
Column column)
Adds the given column to this table at the given position in the column list
|
void |
append(Table tableToAppend) |
void |
clear()
Clears all the data from this table
|
Column |
column(int columnIndex)
Returns the column at the given index in the column list
|
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(java.lang.String columnName)
Returns the index of the column with the given name
|
java.util.List<java.lang.String> |
columnNames()
Returns a List of the names of all the columns in this table
|
java.util.List<Column> |
columns()
Returns the list of columns
|
java.util.List<Column> |
columns(java.lang.String... columnNames)
Returns only the columns whose names are given in the input array
|
Count |
count(java.lang.String numericColumnName) |
Table |
countBy(CategoryColumn column) |
static Table |
create(java.sql.ResultSet resultSet,
java.lang.String tableName)
Returns a new Table with the given name, and containing the data in the given result set
|
static Table |
create(java.lang.String tableName)
Returns a new, empty table (without rows or columns) with the given name
|
static Table |
create(java.lang.String tableName,
Column... columns)
Returns a new table with the given columns and given name
|
static Table |
create(TableMetadata metadata)
Returns a new, empty table constructed according to the given metadata
|
static Table |
createFromCsv(ColumnType[] types,
java.lang.String csvFileName)
Returns a new table constructed from a character delimited (aka CSV) text file
|
static Table |
createFromCsv(ColumnType[] types,
java.lang.String csvFileName,
boolean header)
Returns a new table constructed from a character delimited (aka CSV) text file
|
static Table |
createFromCsv(ColumnType[] types,
java.lang.String csvFileName,
boolean header,
char delimiter)
Returns a new table constructed from a character delimited (aka CSV) text file
|
static Table |
createFromCsv(java.lang.String csvFileName)
Returns a new table constructed from a character delimited (aka CSV) text file
|
static Table |
createFromCsv(java.lang.String csvFileName,
boolean header)
Returns a new table constructed from a character delimited (aka CSV) text file
|
static Table |
createFromCsv(java.lang.String csvFileName,
boolean header,
char delimiter)
Returns a new table constructed from a character delimited (aka CSV) text file
|
static Table |
createFromStream(ColumnType[] types,
boolean header,
char delimiter,
java.io.InputStream stream,
java.lang.String tableName)
Returns a new table constructed from a character delimited (aka CSV) text file
|
Table |
drop(int... rows)
Returns a table
with the given rows dropped
|
Table |
drop(it.unimi.dsi.fastutil.ints.IntArrayList rows)
Returns a table
with the given rows dropped
|
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
|
void |
exportToCsv(java.lang.String fileNameWithPath)
Exports this table as a CSV file with the name (and path) of the given file
|
Table |
first(int nRows)
Returns a new table containing the first
nrows of data in this table |
Table |
fullCopy()
Returns a table with the same columns as this table, but no data
|
java.lang.String |
get(int c,
int r)
Returns a string representation of the value at the given row and column indexes
|
it.unimi.dsi.fastutil.ints.IntComparator |
getComparator(Sort key)
Returns a comparator that can be used to sort the records in this table according to the given sort key
|
static Sort |
getSort(java.lang.String... columnNames)
Returns an object that can be used to sort this table in the order specified for by the given column names
|
it.unimi.dsi.fastutil.ints.IntIterator |
iterator() |
Table |
last(int nRows)
Returns a new table containing the last
nrows of data in this table |
Maximum |
max(java.lang.String numericColumnName) |
Mean |
mean(java.lang.String numericColumnName) |
Median |
median(java.lang.String numericColumnName) |
Minimum |
minimum(java.lang.String numericColumnName) |
java.lang.String |
name()
Returns the name of the table
|
java.lang.String |
printHtml() |
static Table |
readTable(java.lang.String tableNameAndPath) |
double |
reduce(java.lang.String numericColumnName,
NumericReduceFunction function)
Returns the result of applying the given function to the specified column
|
void |
removeColumns(Column... columns)
Removes the given columns
|
void |
retainColumns(Column... columns)
Removes the given columns
|
void |
retainColumns(java.lang.String... columnNames) |
int |
rowCount()
Returns the number of rows in the table
|
int[] |
rows()
Returns an array of ints of the same number of rows as the table
|
Table |
sample(double proportion)
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
|
java.lang.String |
save(java.lang.String folder) |
Projection |
select(java.lang.String... columnName) |
BooleanColumn |
selectIntoColumn(java.lang.String newColumnName,
Filter filter) |
BooleanColumn |
selectIntoColumn(java.lang.String newColumnName,
Selection selection) |
Table |
selectWhere(Filter filter) |
Table |
selectWhere(Selection selection) |
void |
setName(java.lang.String name)
Sets the name of the table
|
Table |
sortAscendingOn(java.lang.String... columnNames)
Returns a copy of this table sorted in the order of the given column names, in ascending order
|
Table |
sortDescendingOn(java.lang.String... columnNames)
Returns a copy of this table sorted on the given column names, applied in order, descending
|
Table |
sortOn(it.unimi.dsi.fastutil.ints.IntComparator rowComparator)
Returns a copy of this table sorted using the given comparator
|
Table |
sortOn(Sort key) |
Table |
sortOn(java.lang.String... columnNames)
Returns a copy of this table sorted on the given column names, applied in order,
|
ViewGroup |
splitOn(Column... columns) |
StandardDeviation |
stdDev(java.lang.String numericColumnName) |
Table |
structure() |
Sum |
sum(java.lang.String numericColumnName) |
SummaryFunction |
summarize(java.lang.String numericColumnName,
NumericReduceFunction function) |
java.lang.String |
toString()
Joins together this table and another table on the given column names.
|
Table |
uniqueRecords()
Returns the unique records in this table
Note: Uses a lot of memory for a sort
|
Variance |
variance(java.lang.String numericColumnName) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
booleanColumn, booleanColumn, categoryColumn, categoryColumn, column, columnTypes, colWidths, dateColumn, dateColumn, dateTimeColumn, dateTimeColumn, floatColumn, floatColumn, intColumn, intColumn, isEmpty, longColumn, longColumn, nCol, nCol, numericColumn, numericColumn, print, removeColumn, removeColumns, shape, shortColumn, shortColumn, summary, timeColumn, timeColumn
protected Table(java.lang.String name, Column... columns)
name
- The name of the tablecolumns
- One or more columns, all of which must have either the same length or size 0public static Table create(java.lang.String tableName)
public static Table create(TableMetadata metadata)
public static Table create(java.lang.String tableName, Column... columns)
columns
- One or more columns, all of the same @code{column.size()}public void addColumn(Column... cols)
public void addColumn(int index, Column column)
index
- Zero-based index into the column listcolumn
- Column to be addedpublic void setName(java.lang.String name)
public Column column(int columnIndex)
public int columnCount()
columnCount
in interface Relation
public int rowCount()
public java.util.List<Column> columns()
public java.util.List<Column> columns(java.lang.String... columnNames)
public int columnIndex(java.lang.String columnName)
columnIndex
in interface Relation
java.lang.IllegalArgumentException
- if the input string is not the name of any column in the tablepublic int columnIndex(Column column)
columnIndex
in interface Relation
java.lang.IllegalArgumentException
- if the column is not present in this tablepublic java.lang.String name()
public java.util.List<java.lang.String> columnNames()
columnNames
in interface Relation
public java.lang.String get(int c, int r)
public Table fullCopy()
public Table emptyCopy()
public Table emptyCopy(int rowSize)
public Table[] sampleSplit(double table1Proportion)
table1Proportion
- The proportion to go in the first tablepublic Table sample(double proportion)
proportion
- The proportion to go in the samplepublic void clear()
public Table first(int nRows)
nrows
of data in this tablepublic Table last(int nRows)
nrows
of data in this tablepublic Table sortOn(java.lang.String... columnNames)
if column name starts with - then sort that column descending otherwise sort ascending
public Table sortAscendingOn(java.lang.String... columnNames)
public Table sortDescendingOn(java.lang.String... columnNames)
public static Sort getSort(java.lang.String... columnNames)
public it.unimi.dsi.fastutil.ints.IntComparator getComparator(Sort key)
public Table sortOn(it.unimi.dsi.fastutil.ints.IntComparator rowComparator)
public int[] rows()
public BooleanColumn selectIntoColumn(java.lang.String newColumnName, Selection selection)
public BooleanColumn selectIntoColumn(java.lang.String newColumnName, Filter filter)
public java.lang.String printHtml()
public Table drop(it.unimi.dsi.fastutil.ints.IntArrayList rows)
rows
- the rows to droppublic Table drop(int... rows)
rows
- the rows to droppublic Table uniqueRecords()
public Projection select(java.lang.String... columnName)
public void removeColumns(Column... columns)
removeColumns
in interface Relation
public void retainColumns(Column... columns)
public void retainColumns(java.lang.String... columnNames)
public Sum sum(java.lang.String numericColumnName)
public Mean mean(java.lang.String numericColumnName)
public Median median(java.lang.String numericColumnName)
public Variance variance(java.lang.String numericColumnName)
public StandardDeviation stdDev(java.lang.String numericColumnName)
public Count count(java.lang.String numericColumnName)
public Maximum max(java.lang.String numericColumnName)
public Minimum minimum(java.lang.String numericColumnName)
public void append(Table tableToAppend)
public void exportToCsv(java.lang.String fileNameWithPath)
fileNameWithPath
- The name of the file to save to. By default, it writes to the working directory,
but you can specify a different folder by providing the path (e.g. mydata/myfile.csv)public java.lang.String save(java.lang.String folder)
public static Table readTable(java.lang.String tableNameAndPath)
public double reduce(java.lang.String numericColumnName, NumericReduceFunction function)
numericColumnName
- The name of a numeric (integer, float, etc.) column in this tablefunction
- A numeric reduce functionjava.lang.IllegalArgumentException
- if numericColumnName doesn't name a numeric column in this tablepublic SummaryFunction summarize(java.lang.String numericColumnName, NumericReduceFunction function)
public Table countBy(CategoryColumn column)
public static Table createFromCsv(java.lang.String csvFileName) throws java.io.IOException
It is assumed that the file is truly comma-separated, and that the file has a one-line header, which is used to populate the column names
csvFileName
- The name of the file to importjava.io.IOException
public static Table createFromCsv(java.lang.String csvFileName, boolean header) throws java.io.IOException
It is assumed that the file is truly comma-separated, and that the file has a one-line header, which is used to populate the column names
csvFileName
- The name of the file to importheader
- True if the file has a single header row. False if it has no header row.
Multi-line headers are not supportedjava.io.IOException
public static Table createFromCsv(java.lang.String csvFileName, boolean header, char delimiter) throws java.io.IOException
It is assumed that the file is truly comma-separated, and that the file has a one-line header, which is used to populate the column names
csvFileName
- The name of the file to importheader
- True if the file has a single header row. False if it has no header row.
Multi-line headers are not supporteddelimiter
- a char that divides the columns in the source file, often a comma or tabjava.io.IOException
public static Table createFromCsv(ColumnType[] types, java.lang.String csvFileName) throws java.io.IOException
It is assumed that the file is truly comma-separated, and that the file has a one-line header, which is used to populate the column names
types
- The column typescsvFileName
- The name of the file to importjava.io.IOException
public static Table createFromCsv(ColumnType[] types, java.lang.String csvFileName, boolean header) throws java.io.IOException
It is assumed that the file is truly comma-separated
types
- The column typesheader
- True if the file has a single header row. False if it has no header row.
Multi-line headers are not supportedcsvFileName
- the name of the file to importjava.io.IOException
public static Table createFromCsv(ColumnType[] types, java.lang.String csvFileName, boolean header, char delimiter) throws java.io.IOException
types
- The column typesheader
- true if the file has a single header row. False if it has no header row.
Multi-line headers are not supporteddelimiter
- a char that divides the columns in the source file, often a comma or tabcsvFileName
- the name of the file to importjava.io.IOException
public static Table createFromStream(ColumnType[] types, boolean header, char delimiter, java.io.InputStream stream, java.lang.String tableName) throws java.io.IOException
types
- The column typesheader
- true if the file has a single header row. False if it has no header row.
Multi-line headers are not supporteddelimiter
- a char that divides the columns in the source file, often a comma or tabstream
- an InputStream from a file, URL, etc.tableName
- the name of the resulting tablejava.io.IOException
public static Table create(java.sql.ResultSet resultSet, java.lang.String tableName) throws java.sql.SQLException
java.sql.SQLException
public java.lang.String toString()
toString
in class java.lang.Object
other
tablepublic it.unimi.dsi.fastutil.ints.IntIterator iterator()
iterator
in interface it.unimi.dsi.fastutil.ints.IntIterable
iterator
in interface java.lang.Iterable<java.lang.Integer>