---
title: Execute python script
description: Runs a custom Python script on input data using a managed Python environment and returns the modified dataset.
category: Data Transforms
tags: [python, script, transform, data, advanced]
---

# Execute python script

## Description

The **Execute python script** activity enables you to run custom Python code on your structured data within the workflow. This activity is ideal for advanced transformations, modeling, calculations, or applying external Python libraries not natively supported by the platform.

- Your code must use a `df` DataFrame as the input, which is automatically injected from the input data.
- The final result must be a modified `df`, which will be returned as tabular data.
- Output must be printed using `print(result_json)` as a JSON string.

> **Use case**: You can apply advanced statistical transformations, encode text, or apply models using libraries like `pandas`, `scikit-learn`, or `numpy` within a workflow step using this activity.

## Input

- **Data** – Required  
  Tabular data passed as a DataFrame (`df`) into the script.

## Output

| Output Type | Format  | Description                           |
| ----------- | ------- | ------------------------------------- |
| **Data**    | Tabular | Output of the modified `df` DataFrame |

## Configuration Fields

| Field Name | Description                                                                           |
| ---------- | ------------------------------------------------------------------------------------- |
| **Code**   | Python code to run. Input data is provided as a DataFrame named `df`. Required field. |

## Sample Input

| Item  | Score |
| ----- | ----- |
| Pen   | 3.5   |
| Book  | 4.7   |
| Chair | 2.9   |

## Sample Configuration

```python
df['Score'] = df['Score'] * 10
df['Category'] = df['Score'].apply(lambda x: 'High' if x > 30 else 'Low')
```

## Sample Output

| Item  | Score | Category |
| ----- | ----- | -------- |
| Pen   | 35.0  | High     |
| Book  | 47.0  | High     |
| Chair | 29.0  | Low      |
