Loading...

verticapy.vDataFrame.explode_array#

vDataFrame.explode_array(index: str, column: str, prefix: str | None = 'col_', delimiter: bool | None = True) vDataFrame#

Returns exploded vDataFrame of array-like columns in a vDataFrame.

New in version 10.0.0.

Parameters#

index: str

Index used to identify the Row.

column: str

The name of the array-like column to explode.

prefix: str, optional

The prefix for the column names of exploded values defaults to “col_”.

delimeter: str, optional

Specify if array-like data is separated by a comma defaults value is True.

Returns#

vDataFrame

horizontal exploded vDataFrame.

Examples#

Let’s begin by importing VerticaPy.

import verticapy as vp

Hint

By assigning an alias to verticapy, we mitigate the risk of code collisions with other libraries. This precaution is necessary because verticapy uses commonly known function names like “average” and “median”, which can potentially lead to naming conflicts. The use of an alias ensures that the functions from verticapy are used as intended without interfering with functions from other libraries.

For this example, let’s generate a dataset:

data = vp.vDataFrame(
    {
        "id": [1, 2, 3, 4],
        "values": [
            [70, 80, 90, 5],
            [47, 34, 93, 20, 13, 16],
            [1, 45, 56, 21, 10, 35, 56, 8, 39],
            [89],
        ]
    }
)

We can compute the exploded vDataFrame.

data.explode_array(index = "id", column = "values")
123
id
Integer
100%
...
123
col_0
Float(22)
100%
123
col_8
Float(22)
25%
11...70.0[null]
23...1.039.0
32...47.0[null]
44...89.0[null]

Note

This function operates on various data types, including arrays and varchar representations of arrays. For arrays with elements separated by commas, as well as varchar representations of arrays with no delimiter (in which case you must specify delimiter as False).

See also

vDataFrame.pivot() : Pivots the vDataFrame.