select
The select
method creates a new in-memory table that includes one column for each argument. Any columns not specified in the arguments will not appear in the resulting table.
When using select
, the entire requested dataset is evaluated and stored in memory.
The syntax for the select
and view
methods is identical, as is the resulting table. select
is recommended when:
- not all the source columns are desired in the result,
- the formula is expensive to evaluate,
- cells are accessed many times, and/or
- a large amount of memory is available.
When memory usage or computation needs to be reduced, consider using view
, update_view
, update
, or lazy_update
. These methods have different memory and computation expenses.
Syntax
select(formulas: Union[str, Sequence[str]]) -> Table
Parameters
Parameter | Type | Description |
---|---|---|
formulas | Union[str, Sequence[str]] | Formulas to compute columns in the new table:
|
Returns
A new in-memory table that includes one column for each argument. If no arguments are provided, there will be one column for each column of the source table.
Examples
In the following example, select
has zero arguments. All columns are selected. While this selection appears to do nothing, it is creating a compact, in-memory representation of the input table, with all formulas evaluated.
from deephaven import new_table
from deephaven.column import string_col, int_col
source = new_table(
[
string_col("A", ["The", "At", "Is", "On"]),
int_col("B", [1, 2, 3, 4]),
int_col("C", [5, 6, 7, 8]),
]
)
result = source.select()
- source
- result
In the following example, column B
is selected for the new table.
from deephaven import new_table
from deephaven.column import string_col, int_col
source = new_table(
[
string_col("A", ["The", "At", "Is", "On"]),
int_col("B", [1, 2, 3, 4]),
int_col("C", [5, 6, 7, 8]),
]
)
result = source.select(formulas=["B"])
- source
- result
In the following example, the new table contains source column A
(renamed as X
), and column B
.
from deephaven import new_table
from deephaven.column import string_col, int_col
source = new_table(
[
string_col("A", ["The", "At", "Is", "On"]),
int_col("B", [1, 2, 3, 4]),
int_col("C", [5, 6, 7, 8]),
]
)
result = source.select(formulas=["X = A", "B"])
- source
- result
In the following example, mathematical operations are evaluated and stored in memory for the new table.
from deephaven import new_table
from deephaven.column import string_col, int_col
source = new_table(
[
string_col("A", ["The", "At", "Is", "On"]),
int_col("B", [1, 2, 3, 4]),
int_col("C", [5, 6, 7, 8]),
]
)
result = source.select(formulas=["A", "X = B", "Y = sqrt(C)"])
- source
- result