Python
Apply a simple single-line python command. For more complex python use a custom function. Note, this evaluates the python command - be especially cautious including variables from untrusted sources within the command string. The python command will be evaluated once for each row and the result returned. Reference column values by using their name. Non-alphanumeric characters within column names are replaced by underscores (_) Additionally, all columns are available as a dict named kwargs. Additional parameters set for the wrangle will also be available to the command.
The Python wrangle executes simple Python commands inline within a recipe. Row values are referenced by column name and commands are evaluated once per row. Spaces within column names are replaced by underscores (_). All columns are also available as a dictionary named kwargs. For more complex Python, use custom functions.
This wrangle evaluates the Python command. Be cautious when including variables from untrusted sources in the command string.
Parameters
| Name | Description | Accepted Values | Default | Required |
|---|---|---|---|---|
| I/O | ||||
output | Name or list of output column(s). To output multiple columns, return a list of the corresponding length. | string, array | — | Yes |
input | Name or list of input column(s) to filter the data available to the command. Useful in conjunction with kwargs to target a variable range of columns. If not specified, all columns will be available. | string, integer, array, null | null | No |
| Options | ||||
command | Python command. This must return a value. Note: any non-alphanumeric characters in variable names are replaced by underscores (_). | string | — | Yes |
| Conditions | ||||
if | Condition that determines whether the wrangle runs as a whole. Recipe variables may be referenced with ${variable}. | string | — | No |
where | Filter rows before applying the wrangle using SQL-like criteria, such as column1 = 123 OR column2 = 'abc'. | string | — | No |
where_params | Values used with where for parameterized criteria. Uses SQLite placeholder syntax such as ? or :name. | array, object | — | No |
| Errors | ||||
except | Value to return for the row if an exception occurs during the evaluation. If not provided, an exception will be raised as normal. If multiple output columns are specified, this must match the length. | string, array, number, integer, boolean, object | — | No |
Examples
wrangles:
- python:
output: result
command: My_Column.upper()
| My Column |
|---|
| example text |
| result |
|---|
| EXAMPLE TEXT |
The Python wrangle supports parameters so values of unknown origin can be injected safely.
wrangles:
- python:
output: sliced
command: input_column[:i]
i: ${var}
No sample available.
No sample available.
Access
| Requirement | Value |
|---|---|
| AI-powered | No |
| Requires WrangleWorks account | No |
| Requires subscription | No |
| Requires external API key | No |
Technical details
| Field | Value |
|---|---|
| Catalog ID | 85 |
| Catalog key | python |
| Recipe key | python |
| Catalog status | active |
| Lifecycle status | active |
| Recipe Writer eligible | Yes |
| Namespace | Root-level |
| Documentation group | compute |
| Aliases | None |
| Runtime symbol | wrangles.recipe_wrangles.main.python |
| Legacy UUID | c0398a11-7731-4e47-8df0-b07eea0b1d6c |
Sources