Skip to content

sample_data

sample_data

generate_cfo_sample_data

generate_cfo_sample_data(
    num_months: int = 12,
    start_date: str = "2025-01-01",
    *,
    num_customers: int = 50,
    seed: int | None = None
) -> DataFrame

Generate sample customer sales data for a CFO demo.

Columns

date: monthly period date customer_id: unique customer identifier customer_name: customer name region: sales region product: product category sales_amount: monthly sales amount units_sold: number of units cost_amount: cost of goods sold margin: sales_amount - cost_amount

Parameters:

Name Type Description Default
num_months int

Number of monthly periods to generate

12
start_date str

First month's date (YYYY-MM-DD)

'2025-01-01'
num_customers int

Number of distinct customers

50
seed int | None

Optional random seed for reproducibility

None

Returns:

Type Description
DataFrame

A pandas DataFrame with one row per customer per month.

Source code in src/crew_dcs/utils/sample_data.py
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
def generate_cfo_sample_data(
    num_months: int = 12,
    start_date: str = "2025-01-01",
    *,
    num_customers: int = 50,
    seed: int | None = None,
) -> pd.DataFrame:
    """Generate sample customer sales data for a CFO demo.

    Columns:
        date: monthly period date
        customer_id: unique customer identifier
        customer_name: customer name
        region: sales region
        product: product category
        sales_amount: monthly sales amount
        units_sold: number of units
        cost_amount: cost of goods sold
        margin: sales_amount - cost_amount

    Args:
        num_months: Number of monthly periods to generate
        start_date: First month's date (YYYY-MM-DD)
        num_customers: Number of distinct customers
        seed: Optional random seed for reproducibility

    Returns:
        A pandas DataFrame with one row per customer per month.
    """
    import numpy as np

    rng = np.random.default_rng(seed)

    dates = pd.date_range(start=start_date, periods=num_months, freq="MS")
    customer_ids = [f"CUST-{i + 1:04d}" for i in range(num_customers)]
    customer_names = [f"Customer {i + 1}" for i in range(num_customers)]
    customer_regions = rng.choice(_REGIONS, size=num_customers)
    customer_products = rng.choice(_PRODUCTS, size=num_customers)

    rows = []
    for date in dates:
        for i in range(num_customers):
            units_sold = int(rng.integers(10, 500))
            sales_amount = round(units_sold * rng.uniform(50, 500), 2)
            cost_amount = round(sales_amount * rng.uniform(0.4, 0.7), 2)
            rows.append(
                {
                    "date": date,
                    "customer_id": customer_ids[i],
                    "customer_name": customer_names[i],
                    "region": customer_regions[i],
                    "product": customer_products[i],
                    "sales_amount": sales_amount,
                    "units_sold": units_sold,
                    "cost_amount": cost_amount,
                    "margin": round(sales_amount - cost_amount, 2),
                }
            )

    return pd.DataFrame(rows)