A ViewColum object represents a column in a View object, which can undergo various transformations depending on its data type.
Generic transforms can be applied to any data type within a view. Find a list of generic transforms in the glossary.
Built-in arithmetic operators (+, -, *, /) can be used to manipulate numeric columns, as shown below:
# Get the view directly from the catalog invoice_view = catalog.get_view("GROCERYINVOICE") # Add a column that measures the Discount ratio items_view["Discount_ratio"] = items_view["Discount"] / items_view["TotalCost"]
Refer to the glossary for additional numeric transforms.
String columns can be concatenated directly:
# Add a column that concatenates two string columns toy_example = ( items_view["Quantity"].astype("str") + " * " + items_view["GroceryProductGuid"] )
Check the glossary for other String transforms.
Datetime columns can be transformed in various ways, such as calculating differences, adding time intervals, or extracting date components. The glossary provides a list of supported dateparts transforms.
Retrieve preceding values associated with a specific entity, using the
ts_col = invoice_view[invoice_view.timestamp_column] invoice_view["InterEventTime"] = ( ts_col - ts_col.lag("GroceryCustomerGuid") ).dt.day
Lags transforms are only supported for Event and Change views.
Apply if-then-else transforms by filtering rows through conditional statements.
# Flag items as discounted, free, or undiscounted discounted_filter = items_view["Discount"] > 0 free_filter = items_view["TotalCost"] == 0 items_view["DiscountCategory"] = "Undiscounted" items_view.DiscountCategory[discounted_filter] = "Discounted" items_view.DiscountCategory[free_filter] = "Free"
Perform exploratory analysis on view columns, such as descriptive statistics, preview, and sample. These operations are executed after cleaning operations set at the table level or during view creation if created in manual mode.
# Obtain descriptive statistics for a view column invoice_view.Amount.describe() # Preview a selection of rows from the view column df = invoice_view.Amount.preview(limit=20) # Sample random rows from the view column based on a specified time range, size, and seed df = invoice_view.sample( from_timestamp=pd.Timestamp('2023-04-01'), to_timestamp=pd.Timestamp('2023-05-01'), size=100, seed=23 )
When extracting a ViewColumn from a View object, a copy of the original object is created. This can be assigned back to the view as a new column or used for further transformations.
# Extract amount amount = invoice_view[‘Amount’] amount.fillna(0) # Assign the transformed amount Series into the view as a new column invoice_view[‘cleaned_amount’] = amount
Defining ViewColumn as a Feature¶
Directly use a view column as a Lookup feature for the entity identified by the view's primary key or the natural key of an SCDView object by using the