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 |
---|---|
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(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
|
Count |
count(String numericColumnName) |
Table |
countBy(CategoryColumn column) |
static Table |
create(ResultSet resultSet,
String tableName)
Deprecated.
use read().db() instead
|
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
|
static Table |
createFromCsv(ColumnType[] types,
String csvFileName)
Deprecated.
use read().csv() instead
|
static Table |
createFromCsv(ColumnType[] types,
String csvFileName,
boolean header)
Deprecated.
use read().csv() instead
|
static Table |
createFromCsv(ColumnType[] types,
String csvFileName,
boolean header,
char delimiter)
Deprecated.
use read().csv() instead
|
static Table |
createFromCsv(InputStream stream,
String tableName,
ColumnType[] types,
boolean header)
Deprecated.
use read().csv() instead
|
static Table |
createFromCsv(String csvFileName)
Deprecated.
use read().csv() instead
|
static Table |
createFromCsv(String csvFileName,
boolean header)
Deprecated.
use read().csv() instead
|
static Table |
createFromCsv(String csvFileName,
boolean header,
char delimiter)
Deprecated.
use read().csv() instead
|
static Table |
createFromCsv(String csvFileName,
boolean header,
char delimiter,
boolean skipSampling)
Deprecated.
use read().csv() instead
|
static Table |
createFromReader(InputStream stream,
String tableName)
Deprecated.
use read().csv() instead
|
static Table |
createFromReader(InputStream stream,
String tableName,
boolean header)
Deprecated.
use read().csv() instead
|
static Table |
createFromReader(InputStream stream,
String tableName,
boolean header,
char delimiter)
Deprecated.
use read().csv() instead
|
static Table |
createFromReader(InputStream stream,
String tableName,
boolean header,
char delimiter,
boolean skipSampling)
Deprecated.
use read().csv() instead
|
static Table |
createFromReader(InputStream stream,
String tableName,
ColumnType[] types,
boolean header,
char delimiter)
Deprecated.
use read().csv() instead
|
Table |
dropRows(int... rows)
Returns a table with the given rows dropped
|
Table |
dropRows(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(String fileNameWithPath)
Deprecated.
use write().csv() instead
|
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
|
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(String numericColumnName) |
Mean |
mean(String numericColumnName) |
Median |
median(String numericColumnName) |
Minimum |
minimum(String numericColumnName) |
String |
name()
Returns the name of the table
|
String |
printHtml() |
static DataFrameReader |
read() |
static Table |
readTable(String tableNameAndPath) |
double |
reduce(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 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 |
selectWhere(Filter filter) |
Table |
selectWhere(Selection selection) |
void |
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) |
StandardDeviation |
stdDev(String numericColumnName) |
Table |
structure() |
Sum |
sum(String numericColumnName) |
SummaryFunction |
summarize(String numericColumnName,
NumericReduceFunction function) |
Table |
uniqueRecords()
Returns the unique records in this table
Note: Uses a lot of memory for a sort
|
Variance |
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, removeColumn, removeColumns, shape, shortColumn, shortColumn, summary, timeColumn, timeColumn, toString, 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)
@Deprecated public static Table createFromCsv(String csvFileName) throws 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 importIOException
- if the file can't be read@Deprecated public static Table createFromReader(InputStream stream, String tableName) throws 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
stream
- The source of the CSVtableName
- The name to give the tableIOException
- if the file can't be read@Deprecated public static Table createFromCsv(String csvFileName, boolean header) throws 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 supportedIOException
- if the file can't be read@Deprecated public static Table createFromReader(InputStream stream, String tableName, boolean header) throws 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
stream
- The source of the CSVtableName
- The name to give the tableheader
- True if the file has a single header row. False if it has no header row.
Multi-line headers are not supportedIOException
- if the file can't be read@Deprecated public static Table createFromCsv(String csvFileName, boolean header, char delimiter) throws 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 tabIOException
- if the file can't be read@Deprecated public static Table createFromReader(InputStream stream, String tableName, boolean header, char delimiter) throws 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
stream
- The source of the CSVtableName
- The name to give the tableheader
- 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 tabIOException
- if the file can't be read@Deprecated public static Table createFromCsv(String csvFileName, boolean header, char delimiter, boolean skipSampling) throws 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 tabskipSampling
- This applies only to column type detection. Column type detection uses sampling to pick a
column type. This may cause the algorithm to skip a row that has information the algorithm
needs. Setting this to true will cause the algorithm to check all the data in the table,
which may take a long time (a couple minutes?) on large tables (over 100,000,000 rows).IOException
- if the file can't be read@Deprecated public static Table createFromReader(InputStream stream, String tableName, boolean header, char delimiter, boolean skipSampling) throws 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
stream
- The source of the CSVtableName
- The name to give the tableheader
- 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 tabskipSampling
- This applies only to column type detection. Column type detection uses sampling to pick a
column type. This may cause the algorithm to skip a row that has information the algorithm
needs. Setting this to true will cause the algorithm to check all the data in the table,
which may take a long time (a couple minutes?) on large tables (over 100,000,000 rows).IOException
- if the file can't be read@Deprecated public static Table createFromCsv(ColumnType[] types, String csvFileName) throws 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 types, (see io.csv.CsvReader to run the heading to create an array you can edit)csvFileName
- The name of the file to importIOException
- if the file can't be read@Deprecated public static Table createFromCsv(ColumnType[] types, String csvFileName, boolean header) throws 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 importIOException
- if the file can't be read@Deprecated public static Table createFromCsv(InputStream stream, String tableName, ColumnType[] types, boolean header) throws IOException
It is assumed that the file is truly comma-separated
stream
- the CSV sourcetableName
- the name to give the tabletypes
- The column typesheader
- True if the file has a single header row. False if it has no header row.
Multi-line headers are not supportedIOException
- if the file can't be read@Deprecated public static Table createFromCsv(ColumnType[] types, String csvFileName, boolean header, char delimiter) throws 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 importIOException
- if the file can't be read@Deprecated public static Table createFromReader(InputStream stream, String tableName, ColumnType[] types, boolean header, char delimiter) throws IOException
stream
- The source of the CSVtableName
- name to give the tabletypes
- 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 tabtableName
- the name of the resulting tableIOException
@Deprecated public static Table create(ResultSet resultSet, String tableName) throws SQLException
SQLException
public static DataFrameReader read()
public DataFrameWriter write()
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(String name)
public 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 String printHtml()
public Table dropRows(it.unimi.dsi.fastutil.ints.IntArrayList rows)
rows
- the rows to droppublic Table dropRows(int... rows)
rows
- the rows to droppublic Table uniqueRecords()
public Projection select(String... columnName)
public void 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 StandardDeviation stdDev(String numericColumnName)
public void append(Table tableToAppend)
@Deprecated public void exportToCsv(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 double reduce(String numericColumnName, NumericReduceFunction function)
numericColumnName
- The name of a numeric (integer, float, etc.) column in this tablefunction
- A numeric reduce functionIllegalArgumentException
- if numericColumnName doesn't name a numeric column in this tablepublic SummaryFunction summarize(String numericColumnName, NumericReduceFunction 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.