verticapy.vDataFrame.flat_vmap¶
- vDataFrame.flat_vmap(vmap_col: Annotated[str | list[str] | StringSQL | list[StringSQL], ''] | None = None, limit: int = 100, exclude_columns: Annotated[str | list[str], 'STRING representing one column or a list of columns'] | None = None) vDataFrame¶
Flatten the selected VMap. A new vDataFrame is returned.
Warning
This function might have a long runtime and can make your vDataFrame less performant. It makes many calls to the MAPLOOKUP function, which can be slow if your VMap is large.
Parameters¶
- vmap_col: SQLColumns, optional
List of VMap columns to flatten.
- limit: int, optional
Maximum number of keys to consider for each VMap. Only the most occurent keys are used.
- exclude_columns: SQLColumns, optional
List of VMap columns to exclude.
Returns¶
- vDataFrame
object with the flattened VMaps.
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 fromverticapyare used as intended without interfering with functions from other libraries.For this example, let’s generate a dataset that has a VMAP in one column:
vdf = vp.vDataFrame( { "id": [1], "team": ['{"country" : "France", "region" : "IDF"}'], } )
123id100%Abc100%1 1 Note
We can observe that our string follows the structure of a JSON. VerticaPy will automatically parse it and determine how to extract the elements.
In order to utilize Vertica Flex Table auto-parsing, it is necessary to convert the string column ‘team’ to a vmap.
vdf["team"].astype('vmap')
123id100%🛠100%1 1 Now we can flatten the vmap:
vdf.flat_vmap()
123id100%... 🛠100%Abcteam.country100%1 1 ... France Note
This function is applicable for flattening Flex tables VMAP. However, it is advisable to store the final result in a table, as the computations involved can be resource-intensive.
See also
vDataFrame.merge_similar_names(): Merges columns with similar names.vDataFrame.pivot(): Pivots the vDataFrame.