Loading...

verticapy.core.tablesample.base.TableSample#

class verticapy.core.tablesample.base.TableSample(values: dict | None = None, dtype: dict | None = None, count: int = 0, offset: int = 0, percent: dict | None = None, max_columns: int = -1)#

TableSample sits at the transition from ‘Big Data’ to ‘Small Data’. This object allows you to conveniently display your results without dependencies on any other modules. It stores the aggregated result in-memory and can then be transformed into a pandas.DataFrame or vDataFrame.

Parameters#

values: dict, optional

Dictionary of columns (keys) and their values. The dictionary must be in the following format: {"column1": [val1, ..., valm], ... "columnk": [val1, ..., valm]}

dtype: dict, optional

Columns data types.

count: int, optional

Number of elements to render when loading the entire dataset. This is used only for rendering purposes.

offset: int, optional

Number of elements to skip when loading the entire dataset. This is used only for rendering purposes.

percent: dict, optional

Dictionary of missing values (Used to display the percent bars)

max_columns: int, optional

Maximum number of columns to display.

Attributes#

The object attributes are the same as the input parameters.

Examples#

Let’s import the TableSample object:

from verticapy import TableSample

Let’s build an example object.

# dict with all the data.
d = {
    "customer_ID": [0, 1, 2, 3],
    "age": [40, 30, 22, 55],
    "name": ['Roger', 'Maria', 'Alisia', 'Costi'],
}


# creating the object.
tb = TableSample(d)
customer_ID
age
name
1040Roger
2130Maria
3222Alisia
4355Costi
Rows: 1-4 | Columns: 3

Let’s use multiple functions.

# Shape.
tb.shape()
Out[4]: (3, 4)

# TableSample columns.
tb.get_columns()
Out[5]: ['customer_ID', 'age', 'name']

# Exporting to list.
tb.to_list()
Out[6]: [[0, 40, 'Roger'], [1, 30, 'Maria'], [2, 22, 'Alisia'], [3, 55, 'Costi']]

# Exporting to pandas.DataFrame.
tb.to_pandas()
Out[7]: 
   customer_ID  age    name
0            0   40   Roger
1            1   30   Maria
2            2   22  Alisia
3            3   55   Costi

# Exporting to SQL.
print(tb.to_sql())
(SELECT 0 AS "customer_ID", 40 AS "age", 'Roger' AS "name") UNION ALL (SELECT 1 AS "customer_ID", 30 AS "age", 'Maria' AS "name") UNION ALL (SELECT 2 AS "customer_ID", 22 AS "age", 'Alisia' AS "name") UNION ALL (SELECT 3 AS "customer_ID", 55 AS "age", 'Costi' AS "name")

Note

Explore TableSample different methods to see more examples.

See also

vDataFrame : Main VerticaPy dataset object.
__init__(values: dict | None = None, dtype: dict | None = None, count: int = 0, offset: int = 0, percent: dict | None = None, max_columns: int = -1) None#

Methods

__init__([values, dtype, count, offset, ...])

append(tbs)

Appends the input TableSample to a target TableSample.

category(column)

Returns the category of data in a specified TableSample column.

decimal_to_float()

Converts all the TableSample decimals to floats.

get_columns()

Returns the TableSample columns.

merge(tbs)

Merges the input TableSample to a target TableSample.

narrow([use_number_as_category])

Returns the narrow representation of the TableSample.

read_sql(query[, title, max_columns, ...])

Returns the result of a SQL query as a TableSample object.

shape()

Computes the TableSample shape.

sort(column[, desc])

Sorts the TableSample using the input column.

to_list()

Converts the TableSample to a list.

to_numpy()

Converts the TableSample to a Numpy array.

to_pandas()

Converts the TableSample to a pandas.DataFrame.

to_sql()

Generates the SQL query associated to the TableSample.

to_vdf()

Converts the TableSample to a vDataFrame.

transpose()

Transposes the TableSample.

Attributes

object_type