public class Table extends Relation implements it.unimi.dsi.fastutil.ints.IntIterable
Tables are the main data-type and primary focus of Tablesaw.
Modifier | Constructor and Description |
---|---|
protected |
Table(String name,
Column... columns)
Returns a new Table initialized with the given names and columns
|
Modifier and Type | Method and Description |
---|---|
Table |
addColumn(Column... cols)
Adds the given column to this table
|
Table |
addColumn(int index,
Column column)
Adds the given column to this table at the given position in the column list
|
double |
agg(String numericColumnName,
AggregateFunction function)
Returns the result of applying the given aggregate function to the specified column
|
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(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
|
List<Column> |
columns(String... columnNames)
Returns only the columns whose names are given in the input array
|
SummaryFunction |
count(String numericColumnName) |
Table |
countBy(CategoryColumn column) |
static Table |
create(String tableName)
Returns a new, empty table (without rows or columns) with the given name
|
static Table |
create(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
|
Table |
dropRows(Collection<Integer> rows)
Returns a table with the given rows dropped
|
Table |
dropRows(int start,
int end)
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
|
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
|
String |
get(int r,
int c)
Returns a string representation of the value at the given row and column indexes
|
Column |
getAndRemoveColumn(int columnIndex)
Removes the given column from this table and returns it
|
Column |
getAndRemoveColumn(String columnName)
Removes the given column from this table and returns it
|
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
|
int |
getFirst(Column column,
String value)
Returns the first row for which the column
columnName contains value , or
null if there are no matches
TODO(lwhite) This is a toy implementation badly in need of rewrite for performance. |
static Sort |
getSort(String... columnNames)
Returns an object that can be used to sort this table in the order specified for by the given column names
|
ViewGroup |
groupBy(Column... columns)
The first stage of a split-apply-combine operation
|
ViewGroup |
groupBy(String... columns)
The first stage of a split-apply-combine operation
|
it.unimi.dsi.fastutil.ints.IntIterator |
iterator() |
Table |
last(int nRows)
Returns a new table containing the last
nrows of data in this table |
SummaryFunction |
max(String numericColumnName) |
SummaryFunction |
mean(String numericColumnName) |
SummaryFunction |
median(String numericColumnName) |
SummaryFunction |
min(String numericColumnName) |
String |
name()
Returns the name of the table
|
String |
printHtml() |
static DataFrameReader |
read() |
static Table |
readTable(String tableNameAndPath) |
Table |
removeColumns(Column... columns)
Removes the given columns
|
void |
retainColumns(Column... columns)
Removes the given columns from this table
|
void |
retainColumns(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
|
String |
save(String folder) |
Projection |
select(String... columnName) |
BooleanColumn |
selectIntoColumn(String newColumnName,
Filter filter) |
BooleanColumn |
selectIntoColumn(String newColumnName,
Selection selection) |
Table |
selectRows(Collection<Integer> rows)
Returns a table with the given rows selected
|
Table |
selectRows(int start,
int end)
Returns a table with the given rows selected
|
Table |
selectWhere(Filter filter) |
Table |
selectWhere(Selection selection) |
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
|
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(String... columnNames)
Returns a copy of this table sorted on the given column names, applied in order,
|
ViewGroup |
splitOn(Column... columns)
Synonymous with groupBy
The first stage of a split-apply-combine operation
|
ViewGroup |
splitOn(String... columns)
Synonymous with groupBy
The first stage of a split-apply-combine operation
|
SummaryFunction |
stdDev(String numericColumnName) |
Table |
structure() |
SummaryFunction |
sum(String numericColumnName) |
SummaryFunction |
summarize(String numericColumnName,
AggregateFunction function) |
Table |
uniqueRecords()
Returns the unique records in this table
Note: Uses a lot of memory for a sort
|
SummaryFunction |
variance(String numericColumnName) |
DataFrameWriter |
write() |
booleanColumn, booleanColumn, categoryColumn, categoryColumn, column, columnTypes, colWidths, dateColumn, dateColumn, dateTimeColumn, dateTimeColumn, doubleColumn, doubleColumn, floatColumn, floatColumn, intColumn, intColumn, isEmpty, longColumn, longColumn, nCol, nCol, numericColumn, numericColumn, print, print, removeColumn, removeColumns, shape, shortColumn, shortColumn, summary, timeColumn, timeColumn, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
forEach, spliterator
public static Table create(String tableName)
public static Table create(TableMetadata metadata)
public static Table create(String tableName, Column... columns)
columns
- One or more columns, all of the same @code{column.size()}public static Sort getSort(String... columnNames)
public static DataFrameReader read()
public DataFrameWriter write()
public Table addColumn(int index, Column column)
index
- Zero-based index into the column listcolumn
- Column to be addedpublic Column column(int columnIndex)
public int columnCount()
columnCount
in class Relation
public int rowCount()
public List<Column> columns(String... columnNames)
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 String get(int r, int c)
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 Table first(int nRows)
nrows
of data in this tablepublic Table last(int nRows)
nrows
of data in this tablepublic 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 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(String newColumnName, Selection selection)
public BooleanColumn selectIntoColumn(String newColumnName, Filter filter)
public ViewGroup groupBy(String... columns)
public ViewGroup groupBy(Column... columns)
public ViewGroup splitOn(String... columns)
public ViewGroup splitOn(Column... columns)
public String printHtml()
public Table selectRows(Collection<Integer> rows)
rows
- the rows to selectpublic Table selectRows(int start, int end)
start
- the first row to selectend
- the last row to selectpublic Table dropRows(Collection<Integer> rows)
rows
- the rows to droppublic Table dropRows(int start, int end)
start
- the first row to dropend
- the last row to droppublic Table uniqueRecords()
public Projection select(String... columnName)
public Table removeColumns(Column... columns)
removeColumns
in class Relation
public Column getAndRemoveColumn(String columnName)
IllegalStateException
- if the given columnName does not match the name of a column in the tablepublic Column getAndRemoveColumn(int columnIndex)
IndexOutOfBoundsException
- if the given columnIndex does not match any column in the tablepublic void retainColumns(Column... columns)
public void retainColumns(String... columnNames)
public SummaryFunction sum(String numericColumnName)
public SummaryFunction mean(String numericColumnName)
public SummaryFunction median(String numericColumnName)
public SummaryFunction variance(String numericColumnName)
public SummaryFunction stdDev(String numericColumnName)
public SummaryFunction count(String numericColumnName)
public SummaryFunction max(String numericColumnName)
public SummaryFunction min(String numericColumnName)
public void append(Table tableToAppend)
public double agg(String numericColumnName, AggregateFunction function)
numericColumnName
- The name of a numeric (integer, float, etc.) column in this tablefunction
- An aggregation functionIllegalArgumentException
- if numericColumnName doesn't name a numeric column in this tablepublic SummaryFunction summarize(String numericColumnName, AggregateFunction function)
public Table countBy(CategoryColumn column)
public int getFirst(Column column, String value)
columnName
contains value
, or
null if there are no matches
TODO(lwhite) This is a toy implementation badly in need of rewrite for performance.Copyright © 2017. All rights reserved.