Package tech.tablesaw.columns
Interface Column<T>
- All Superinterfaces:
Comparator<T>
,Iterable<T>
- All Known Subinterfaces:
BooleanMapUtils
,CategoricalColumn<T>
,DateFilters
,DateMapFunctions
,DateTimeFilters
,DateTimeMapFunctions
,NumericColumn<T>
,StringFilters
,StringMapFunctions
,StringReduceUtils
,TemporalColumn<T>
,TemporalFilters<T>
,TemporalMapFunctions<C,
,T> TimeFilters
,TimeMapFunctions
- All Known Implementing Classes:
AbstractColumn
,AbstractStringColumn
,BooleanColumn
,DateColumn
,DateTimeColumn
,DoubleColumn
,FloatColumn
,InstantColumn
,IntColumn
,LongColumn
,NumberColumn
,ShortColumn
,StringColumn
,TextColumn
,TimeColumn
The general interface for columns.
Columns can either exist on their own or be a part of a table. All the data in a single column is of a particular type.
-
Method Summary
Modifier and TypeMethodDescriptiondefault boolean
Returns true if all rows satisfy the predicate, false otherwisedefault boolean
Returns true if any row satisfies the predicate, false otherwiseAppends value to the bottom of this column and return this columnAppends all the values in the argument to the bottom of this column and return this columnAppends the value at the given row in the given column to the bottom of this column and return this columnappendCell
(String stringValue) Add one element to the bottom of this column and set its value to the parsed value of the given String.appendCell
(String stringValue, AbstractColumnParser<?> parser) Add one element to the bottom of this column and set its value to the parsed value of the given String, as performed by the given parserAppends a missing value appropriate to the columnAppends the given value to the bottom of this column and return this columnbyte[]
asBytes
(int rowNumber) Returns the contents of the cell at rowNumber as a byte[].asList()
Returns a list of all the elements in this columnT[]
Returns an array of objects as appropriate for my type of columnasSet()
Returns a Set containing all the unique values in this columnReturns a StringColumn consisting of the (unformatted) String representation of this column valuesint
byteSize()
Returns the width of a cell in this column, in bytes.void
clear()
Removes all elements TODO: Make this return this columndefault int
Returns the width of the column in characters, for printingdefault boolean
Returnstrue
if the given object appears in this column, and false otherwisecopy()
Returns a deep copy of the receiverdefault int
Counts the number of rows satisfying predicatedefault int
Counts the number of rows satisfying predicate, but only upto the max valueint
Returns the count of missing values in this column.default int
Returns the count of unique values in this column.Returns a copy of the receiver with no data.emptyCopy
(int rowSize) Returns an empty copy of the receiver, with its internal storage initialized to the given row size.boolean
equals
(int rowNumber1, int rowNumber2) Returns true if the value in this column at rowNumber1 is equal to the value at rowNumber2Returns a new Column of the same type with only those rows satisfying the predicatefirst
(int numRows) Returns a column of the same type containing the firstnumRows
of this column.get
(int row) Returns the value at the given zero-based indexgetString
(int row) Returns a string representation of the value at the given row.getUnformattedString
(int r) Returns a String representation of the value at index r, without any formatting appliedint
Returns the index of the first occurrence ofo
in the column or -1 if the element is not in the column.inRange
(int start, int end) Returns a column containing the rows in this column beginning with start inclusive, and ending with end exclusivedefault Interpolator<T>
Provides the ability to create a new column with missing cells filled based off the value of nearby cells.boolean
isEmpty()
Returns true if the column has no dataReturns a selection containing an index for every missing value in this columnboolean
isMissing
(int rowNumber) Returns true if the value at rowNumber is missingReturns a selection containing an index for every non-missing value in this columnlag
(int n) Returns a column of the same type and size as the receiver, containing the receivers values offset by n.last
(int numRows) Returns a column of the same type containing the lastnumRows
of this column.lead
(int n) Returns a column of the same type as the receiver, containing the receivers values offset -n For example if you lead a column containing 2, 3, 4 by 1, you get a column containing 3, 4, NA.default <R,
C extends Column<R>>
CMaps the function across all rows, appending the results to the created Column.Maps the function across all rows, appending the results to a new Column of the same typedefault <R,
C extends Column<R>>
CMaps the function across all rows, storing the results into the provided Column.max
(Comparator<? super T> comp) Returns the maximum row according to the provided ComparatorReturns a column containing the element-wise min between this column and other columnmin
(Comparator<? super T> comp) Returns the minimum value according to the provided ComparatorReturns a column containing the element-wise min between this column and other columnname()
Returns the column's name.default boolean
Returns true if no row satisfies the predicate, false otherwiseparser()
Returns the parser used byappendCell(String)
()}.default String
print()
TODO(lwhite): Print n from the top and bottom, like a table;reduce
(BinaryOperator<T> op) Reduction with binary operatordefault T
reduce
(T initial, BinaryOperator<T> op) Reduction with binary operator and initial valueReturns a copy of this column with the missing values removeddefault RollingColumn
rolling
(int windowSize) Returns aRollingColumn
with the given windowSize, which can be used for performing calculations on rolling subsets of my datait.unimi.dsi.fastutil.ints.IntComparator
Returns an IntComparator for sorting my rowssampleN
(int n) Returns a column containing a random sample of the values in this columnsampleX
(double proportion) Returns a table consisting of randomly selected values from this column.set
(int row, String stringValue, AbstractColumnParser<?> parser) Sets the value at row to the parsed value of the given String using the given parser and returns this columnSets the value at index row to the given value and return this columnSets the value at row to the value at sourceRow in the given column and return this columnUpdates this column where values matching the selection are replaced with the corresponding value from the given columnConditionally update this column, replacing current values with newValue for all rows where the current value matches the selection criteriaUpdates this column where values matching the selection are replaced with the corresponding value from the given columnsetMissing
(int i) Sets the value at index i to the missing-value indicator for this column type, and return this columnsetMissingTo
(T newValue) Sets the value of any missing data in the column to newValue and returns the same columnSets the columns name to the given stringsetParser
(AbstractColumnParser<T> parser) Sets the parser used byappendCell(String)
int
size()
Returns the number of elements in this column, including missing valuesvoid
Sorts my values in ascending ordervoid
Sorts my values in descending ordersorted
(Comparator<? super T> comp) Returns a new Column of the same type sorted according to the provided Comparatorsubset
(int[] rows) Return a column of the same type containing just those elements whose indexes are included in the given arraysummary()
Returns a table containing a ColumnType specific summary of the data in this columndefault String
title()
type()
Returns this column's ColumnTypeunique()
Returns a column of the same type containing only the unique valuesint
valueHash
(int rowNumber) Returns an int suitable as a hash for the value in this column at the given indexReturns a new column containing the subset referenced by theSelection
Methods inherited from interface java.util.Comparator
compare, equals, reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
Methods inherited from interface java.lang.Iterable
forEach, iterator, spliterator
-
Method Details
-
size
int size()Returns the number of elements in this column, including missing values -
summary
Table summary()Returns a table containing a ColumnType specific summary of the data in this column -
asObjectArray
T[] asObjectArray()Returns an array of objects as appropriate for my type of column -
countMissing
int countMissing()Returns the count of missing values in this column.- Returns:
- missing values as int
-
countUnique
default int countUnique()Returns the count of unique values in this column.- Returns:
- unique values as int
-
name
String name()Returns the column's name.- Returns:
- name as String
-
type
ColumnType type()Returns this column's ColumnType- Returns:
ColumnType
-
parser
AbstractColumnParser<T> parser()Returns the parser used byappendCell(String)
()}.- Returns:
AbstractColumnParser
-
getString
Returns a string representation of the value at the given row.- Parameters:
row
- The index of the row.- Returns:
- value as String
-
get
Returns the value at the given zero-based index -
reduce
Reduction with binary operator and initial value- Parameters:
initial
- initial valueop
- the operator- Returns:
- the result of reducing initial value and all rows with operator
-
reduce
Reduction with binary operator- Parameters:
op
- the operator- Returns:
- Optional with the result of reducing all rows with operator
-
clear
void clear()Removes all elements TODO: Make this return this column -
sortAscending
void sortAscending()Sorts my values in ascending order -
sortDescending
void sortDescending()Sorts my values in descending order -
isEmpty
boolean isEmpty()Returns true if the column has no data- Returns:
- true if empty, false if not
-
rowComparator
it.unimi.dsi.fastutil.ints.IntComparator rowComparator()Returns an IntComparator for sorting my rows -
title
-
isMissing
Selection isMissing()Returns a selection containing an index for every missing value in this column -
isNotMissing
Selection isNotMissing()Returns a selection containing an index for every non-missing value in this column -
byteSize
int byteSize()Returns the width of a cell in this column, in bytes.- Returns:
- width in bytes
-
asBytes
byte[] asBytes(int rowNumber) Returns the contents of the cell at rowNumber as a byte[].- Parameters:
rowNumber
- index of the row- Returns:
- content as byte[]
-
asSet
Returns a Set containing all the unique values in this column -
rolling
Returns aRollingColumn
with the given windowSize, which can be used for performing calculations on rolling subsets of my data- Parameters:
windowSize
- The number of elements to include in each calculation- Returns:
- a RollingColumn
-
getUnformattedString
Returns a String representation of the value at index r, without any formatting applied -
isMissing
boolean isMissing(int rowNumber) Returns true if the value at rowNumber is missing -
print
TODO(lwhite): Print n from the top and bottom, like a table; -
columnWidth
default int columnWidth()Returns the width of the column in characters, for printing -
asList
Returns a list of all the elements in this columnNote, if a value in the column is missing, a
null
is added in it's place -
contains
Returnstrue
if the given object appears in this column, and false otherwiseTODO override in column subtypes for performance
-
count
Counts the number of rows satisfying predicate, but only upto the max value- Parameters:
test
- the predicatemax
- the maximum number of rows to count- Returns:
- the number of rows satisfying the predicate
-
count
Counts the number of rows satisfying predicate- Parameters:
test
- the predicate- Returns:
- the number of rows satisfying the predicate
-
allMatch
Returns true if all rows satisfy the predicate, false otherwise- Parameters:
test
- the predicate- Returns:
- true if all rows satisfy the predicate, false otherwise
-
anyMatch
Returns true if any row satisfies the predicate, false otherwise- Parameters:
test
- the predicate- Returns:
- true if any rows satisfies the predicate, false otherwise
-
noneMatch
Returns true if no row satisfies the predicate, false otherwise- Parameters:
test
- the predicate- Returns:
- true if no row satisfies the predicate, false otherwise
-
max
Returns the maximum row according to the provided Comparator- Parameters:
comp
-- Returns:
- the maximum row
-
min
Returns the minimum value according to the provided Comparator- Parameters:
comp
- the Comparator to use- Returns:
- the minimum value
-
mapInto
Maps the function across all rows, storing the results into the provided Column.The target column must have at least the same number of rows.
- Parameters:
fun
- function to mapinto
- Column into which results are set- Returns:
- the provided Column
-
map
default <R,C extends Column<R>> C map(Function<? super T, ? extends R> fun, Function<String, C> creator) Maps the function across all rows, appending the results to the created Column.Example:
DoubleColumn d; StringColumn s = d.map(String::valueOf, StringColumn::create);
- Parameters:
fun
- function to mapcreator
- the creator of the Column. Its String argument will be the name of the current column (seename()
)- Returns:
- the Column with the results
-
setMissing
Sets the value at index i to the missing-value indicator for this column type, and return this column -
setMissingTo
Sets the value of any missing data in the column to newValue and returns the same column- Parameters:
newValue
- the value to be used for all missing data in this column- Returns:
- the column updated
-
filter
Returns a new Column of the same type with only those rows satisfying the predicate- Parameters:
test
- the predicate- Returns:
- a new Column of the same type with only those rows satisfying the predicate
-
subset
Return a column of the same type containing just those elements whose indexes are included in the given array -
sorted
Returns a new Column of the same type sorted according to the provided Comparator- Parameters:
comp
- the Comparator- Returns:
- a sorted Column
-
emptyCopy
Returns a copy of the receiver with no data. The column name and type are the same.- Returns:
- a empty copy of
Column
-
copy
Returns a deep copy of the receiver- Returns:
- a
Column
-
emptyCopy
Returns an empty copy of the receiver, with its internal storage initialized to the given row size.- Parameters:
rowSize
- the initial row size- Returns:
- a
Column
-
map
Maps the function across all rows, appending the results to a new Column of the same type- Parameters:
fun
- function to map- Returns:
- the Column with the results
-
min
Returns a column containing the element-wise min between this column and other columnTODO(lwhite) Override in column subtypes for better performance
-
max
Returns a column containing the element-wise min between this column and other columnTODO(lwhite) Override in column subtypes for better performance
-
set
Updates this column where values matching the selection are replaced with the corresponding value from the given column -
set
Updates this column where values matching the selection are replaced with the corresponding value from the given column -
lead
Returns a column of the same type as the receiver, containing the receivers values offset -n For example if you lead a column containing 2, 3, 4 by 1, you get a column containing 3, 4, NA. -
set
Conditionally update this column, replacing current values with newValue for all rows where the current value matches the selection criteria -
lag
Returns a column of the same type and size as the receiver, containing the receivers values offset by n.For example if you lag a column containing 2, 3, 4 by 1, you get a column containing NA, 2, 3
-
appendCell
Add one element to the bottom of this column and set its value to the parsed value of the given String. Parsing is type-specific -
appendCell
Add one element to the bottom of this column and set its value to the parsed value of the given String, as performed by the given parser -
set
Sets the value at index row to the given value and return this column -
set
Sets the value at row to the parsed value of the given String using the given parser and returns this column -
set
Sets the value at row to the value at sourceRow in the given column and return this column -
append
Appends value to the bottom of this column and return this column -
append
Appends all the values in the argument to the bottom of this column and return this column -
append
Appends the value at the given row in the given column to the bottom of this column and return this column -
appendObj
Appends the given value to the bottom of this column and return this column -
appendMissing
Appends a missing value appropriate to the column -
valueHash
int valueHash(int rowNumber) Returns an int suitable as a hash for the value in this column at the given index -
equals
boolean equals(int rowNumber1, int rowNumber2) Returns true if the value in this column at rowNumber1 is equal to the value at rowNumber2 -
where
Returns a new column containing the subset referenced by theSelection
-
removeMissing
Returns a copy of this column with the missing values removed -
unique
Returns a column of the same type containing only the unique values- Returns:
- a
Column
-
first
Returns a column of the same type containing the firstnumRows
of this column. -
last
Returns a column of the same type containing the lastnumRows
of this column. -
setName
Sets the columns name to the given string- Parameters:
name
- The new name MUST be unique for any table containing this column- Returns:
- this Column to allow method chaining
-
setParser
Sets the parser used byappendCell(String)
- Parameters:
parser
- a column parser that converts text input to the column data type- Returns:
- this Column to allow method chaining
-
inRange
Returns a column containing the rows in this column beginning with start inclusive, and ending with end exclusive -
sampleN
Returns a column containing a random sample of the values in this column- Parameters:
n
- the number of values to select- Returns:
- A column of the same type as the receiver
-
sampleX
Returns a table consisting of randomly selected values from this column. The sample size is based on the given proportion of the total number of cells in this column- Parameters:
proportion
- The proportion to go in the sample
-
interpolate
Provides the ability to create a new column with missing cells filled based off the value of nearby cells. -
asStringColumn
StringColumn asStringColumn()Returns a StringColumn consisting of the (unformatted) String representation of this column values- Returns:
- a
StringColumn
built using the columngetUnformattedString(int)
method
-
indexOf
Returns the index of the first occurrence ofo
in the column or -1 if the element is not in the column.
-