Articles in this section

Run a Z-Test in Bold Data Hub Using Python Script and Display Results in Bold BI

Published:

Overview

This article shows you how to run a Python-based Z-test (A/B statistical significance) in Bold ETL (Data Hub), store the output in a destination table, and then visualize the results in Bold BI.

Step-by-Step Instructions

  1. Open DataHub from the Bold BI portal.

    image.png

  2. Create a new Pipeline (or open an existing one).

    • Click Add Pipeline like Ztest_ab_revenue
      image.png
  3. Open the pipeline to access the YAML editor.

    image.png

  4. Add the PythonScript template in the YAML editor.

    • In the left panel, click PythonScript
    • Click Add template
      image.png
  5. Upload your Python script file (.py) to Datahub.

    • Click Upload File
    • Choose your .py script
    • Click GetFilePath and paste the copied file path into the YAML filePath property
      image.png
  6. Click Save and select the destination database configured in Data Store

    image.png

  7. Verify the execution output and confirm the table is created.

    • Open the Pipeline and switch to the Logs tab to review logs.
      image.png
  8. In Bold BI, create a dashboard using the data source created by Datahub

    image.png

CodeSample

Minimal Z-test Python script (A vs B) that outputs a results table

import pandas as pd
import numpy as np
import math

# ✅ Sample dataset (replace with your real incoming data if needed)
data = [
   ['A', 120],
   ['A', 150],
   ['A', 130],
   ['B', 100],
   ['B', 110],
   ['B', 105]
]

columns = ['Campaign', 'Revenue']
df = pd.DataFrame(data, columns=columns)

# ✅ Split groups
groupA = df[df['Campaign'] == 'A']['Revenue'].dropna()
groupB = df[df['Campaign'] == 'B']['Revenue'].dropna()

# ✅ Compute stats
mean_A = groupA.mean()
mean_B = groupB.mean()

std_A = groupA.std(ddof=1)
std_B = groupB.std(ddof=1)

n_A = len(groupA)
n_B = len(groupB)

# ✅ Z-stat
z_stat = (mean_A - mean_B) / np.sqrt((std_A**2 / n_A) + (std_B**2 / n_B))

# ✅ Normal CDF
def normal_cdf(x):
   return (1 + math.erf(x / math.sqrt(2))) / 2

# ✅ P-value
p_value = 2 * (1 - normal_cdf(abs(z_stat)))

# ✅ Significance
significance = "Significant" if p_value < 0.05 else "Not Significant"

# ✅ ✅ Attach stats to every row
df["Mean_A"] = round(mean_A, 2)
df["Mean_B"] = round(mean_B, 2)
df["StdDev_A"] = round(std_A, 2)
df["StdDev_B"] = round(std_B, 2)
df["Count_A"] = n_A
df["Count_B"] = n_B
df["Z_Statistic"] = round(z_stat, 4)
df["P_Value"] = round(p_value, 5)
df["Significance"] = significance

print("Final Dataset with Z-Test:")
print(df)

# ✅ Load to Data Hub
load_info = pipeline.run(df, table_name="z_test_detailed_results")

print("\nLoad Info:")
print(load_info) 

Visualizing in Bold BI (example widgets)

  • Create a Grid widget using z_test_results to show: Z_Stat, P_Value, Revenue.
    image.png

Related Articles

Was this article useful?
Like
Dislike
Help us improve this page
Please provide feedback or comments
DE
Written by Dhanasekaran Ekambaram
Updated:
Comments (0)
Access denied
Access denied