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)¶
TableSamplesits 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 apandas.DataFrameorvDataFrame.Parameters¶
- values: dict, optional
Dictionary of columns (keys) and their values. The
dictionarymust 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
TableSampleobject: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 1 0 40 Roger 2 1 30 Maria 3 2 22 Alisia 4 3 55 Costi Rows: 1-4 | Columns: 3Let’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
TableSampledifferent 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
TableSampleto a targetTableSample.category(column)Returns the category of data in a specified
TableSamplecolumn.Converts all the
TableSampledecimalstofloats.Returns the TableSample columns.
merge(tbs)Merges the input
TableSampleto a targetTableSample.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
TableSampleobject.shape()Computes the
TableSampleshape.sort(column[, desc])Sorts the TableSample using the input column.
to_list()Converts the
TableSampleto alist.to_numpy()Converts the
TableSampleto a Numpy array.Converts the
TableSampleto apandas.DataFrame.to_sql()Generates the SQL query associated to the
TableSample.to_vdf()Converts the
TableSampleto avDataFrame.Transposes the
TableSample.Attributes
object_type