iter_dict
iter_dict
returns a generator that iterates over one row at a time from a table into a dictionary. The dictionary maps column names to scalar values of the corresponding column data types.
If locking is not explicitly specified, this method will automatically lock to ensure that all data from an iteration is from a consistent table snapshot.
Syntax
iter_dict(cols: Optional[Union[str, Sequence[str]]] = None, chunk_size: int = 2048) -> Generator[Dict[str, Any], None, None]
Parameters
Parameter | Type | Description |
---|---|---|
cols | Union[str, Sequence[str]] | The columns to read. If not given, all columns are read. The default is |
chunk_size | int | The number of rows internally read at a time by Deephaven. The default is 2048. |
Returns
A generator that yields a dictionary of column names and scalar column values.
Examples
The following example iterates over a table and prints each value in each row:
from deephaven import empty_table
source = empty_table(6).update(
["X = randomInt(0, 10)", "Y = randomDouble(100, 200)", "Z = randomBool()"]
)
for chunk in source.iter_dict():
x = chunk["X"]
y = chunk["Y"]
z = chunk["Z"]
print(f"X: {x}\tY: {y}\tZ: {z}")
- source
- Log
The following example iterates over a table and prints only the X
and Z
columns:
from deephaven import empty_table
source = empty_table(6).update(
["X = randomInt(0, 10)", "Y = randomDouble(100, 200)", "Z = randomBool()"]
)
for chunk in source.iter_dict(cols=["X", "Z"]):
x = chunk["X"]
z = chunk["Z"]
print(f"X: {x}\tZ: {z}")
- source
- Log