to_table
The to_table
method creates a new table from a pandas.DataFrame
.
Syntax
to_table(
df: pandas.DataFrame,
cols: list[str] = None,
infer_objects: bool = True
) -> Table
Parameters
Parameter | Type | Description |
---|---|---|
df | pandas.DataFrame | The |
cols optional | list[str] | The columns to convert. If not specified, all columns are converted. |
infer_objects optional | bool | Whether to infer the best possible types for columns of the generic |
Returns
A Deephaven Table.
Examples
The following example uses pandas to create a DataFrame, then converts it to a Deephaven Table with to_table
.
from deephaven.pandas import to_table
import pandas as pd
d = {"col1": [1, 2], "col2": [3, 4]}
df = pd.DataFrame(data=d)
result = to_table(df)
- result
- df
The following example uses the cols
parameter to convert only the specified columns.
from deephaven.pandas import to_table
import pandas as pd
d = {"col1": [1, 2], "col2": [3, 4]}
df = pd.DataFrame(data=d)
result = to_table(df, ["col1"])
- result
- df
The following example creates a DataFrame with a generic Object
type column. It then converts it to a table twice: once with infer_objects=True
and once with infer_objects=False
. The metadata for each resulting table is shown to demonstrate the difference in column types.
from deephaven.pandas import to_table
import pandas as pd
df = pd.DataFrame({"A": [1, 2, 3], "B": [1, 2.1, 3], "C": [1, pd.NA, 3]})
result_infer = to_table(df)
result_no_infer = to_table(df, infer_objects=False)
infer_meta = result_infer.meta_table
no_infer_meta = result_no_infer.meta_table
- infer_meta
- no_infer_meta
- result_infer
- result_no_infer
- df