Python Code Guide
You can use the Python Code Node in D.Hub pipelines to transform data or perform analysis logic.
Basic Structure
The Python code node operates based on Polars DataFrame.
Input
- Data from connected previous nodes is passed as a
Polars DataFrame. - The input variable name follows the Input Alias set by the user.
Options
- You can receive runtime variables through the
optionsdictionary defined in the pipeline settings.
Output
- You must return a dictionary with a key named
output. - The value of
outputmust be aPolars DataFrame.
Example Code
import polars as pl
def transform(inputs, options):
# 1. Get input data (when the input alias is 'input_df')
df = inputs['input_df']
# 2. Data transformation logic (e.g., multiply 'count' column by 2)
result_df = df.with_columns(
(pl.col("count") * 2).alias("doubled_count")
)
# 3. Return result
return {
"output": result_df
}
Available Packages
The following packages are included in the environment by default. Additional packages can be specified in the node settings.
polarspandasnumpy