Computational Methods in Data Science Using the Python Programming Language
Computational Methods in Data Science Using the Python Programming Language is a cornerstone topic for every serious data practitioner. Before you touch a single notebook, the decisions framed here shape which problems are worth solving, how value is measured, and which evidence counts as persuasive.
Why Computational Methods Data Matters
Strategic clarity at the start of a project compounds. A well-scoped problem with the right success metric is worth more than any sophisticated model built against a vague goal.
- Frame business goals as measurable analytical questions.
- Distinguish the data problem from the decision problem.
- Identify the smallest experiment that can falsify your hypothesis.
- Design feedback loops that keep strategy aligned with evidence.
How Computational Methods Data Shows Up in Practice
In a typical project, computational methods in data science using the python programming language is combined with the rest of the Strategy & Foundations toolkit. You rarely use any one technique in isolation; the real skill is knowing which combination fits the problem you are trying to solve, and being able to explain that choice to a non-technical stakeholder.
Use these ideas when scoping a new analytics initiative, prioritising between competing proposals, or writing the first page of a data strategy for your team.
- The Strategic Imperative of Data-driven Decision
- Translating Business Objectives into Analytical Frameworks
- Principles of Critical Reasoning and Analytical
- Role Data Science Corporate Strategy Innovation
Back to the Data Science curriculum →
Code Examples: Computational Methods Data Science Using Python (5 runnable snippets)
Copy any block into a file or notebook and run it end-to-end — each example stands alone.
Example 1: A/B test decision summary
# Example 1: A/B test decision summary -- Computational Methods Data Science Using Python
import numpy as np
from scipy import stats
rng = np.random.default_rng(0)
control = rng.binomial(1, 0.118, 5_200)
treatment = rng.binomial(1, 0.134, 5_200)
p_c, p_t = control.mean(), treatment.mean()
lift = (p_t - p_c) / p_c
t, p_val = stats.ttest_ind(control, treatment, equal_var=False)
print(f"control rate : {p_c:.3%}")
print(f"treatment rate : {p_t:.3%}")
print(f"relative lift : {lift:+.1%}")
print(f"p-value : {p_val:.4f}")
print("decision :",
"ship treatment" if (p_val < 0.05 and lift > 0) else "keep control")
Example 2: Customer cohort retention matrix
# Example 2: Customer cohort retention matrix -- Computational Methods Data Science Using Python
import numpy as np
import pandas as pd
rng = np.random.default_rng(0)
n_users, n_months = 1_200, 12
signup = rng.integers(0, 6, n_users) # cohort month 0..5
active = np.zeros((n_users, n_months), dtype=int)
for u in range(n_users):
life = rng.geometric(p=0.18) + 1
end = min(signup[u] + life, n_months)
active[u, signup[u]:end] = 1
df = pd.DataFrame(active, columns=[f"m{i}" for i in range(n_months)])
df["cohort"] = signup
cohorts = (
df.groupby("cohort").mean()
.round(2)
.rename_axis(index="cohort_month")
)
print(cohorts.iloc[:, :8])
Example 3: Monte-Carlo what-if for a pricing change
# Example 3: Monte-Carlo what-if for a pricing change -- Computational Methods Data Science Using Python
import numpy as np
rng = np.random.default_rng(0)
n = 50_000
# Sample plausible inputs from prior beliefs
price_elasticity = rng.normal(-1.1, 0.25, n) # demand % change per 1% price
price_change = 0.08 # +8% list price
baseline_volume = rng.normal(12_000, 800, n)
unit_cost = rng.normal(22.0, 1.5, n)
old_price = 40.0
new_volume = baseline_volume * (1 + price_elasticity * price_change)
old_profit = (old_price - unit_cost) * baseline_volume
new_profit = (old_price * (1 + price_change) - unit_cost) * new_volume
uplift = new_profit - old_profit
print(f"expected uplift : ${uplift.mean():,.0f}")
print(f"5th-95th pct : ${np.percentile(uplift, 5):,.0f} .. "
f"${np.percentile(uplift, 95):,.0f}")
print(f"P(uplift > 0) : {(uplift > 0).mean():.2%}")
Example 4: Weekly KPI roll-up with pandas
# Example 4: Weekly KPI roll-up with pandas -- Computational Methods Data Science Using Python
import pandas as pd
import numpy as np
dates = pd.date_range("2026-01-01", periods=90, freq="D")
rng = np.random.default_rng(42)
df = pd.DataFrame({
"date": dates,
"revenue": rng.normal(12_000, 1500, 90).round(2),
"active_users": rng.integers(8_000, 12_000, 90),
"churned": rng.integers(10, 60, 90),
})
df["arpu"] = df["revenue"] / df["active_users"]
df["churn_rate"] = df["churned"] / df["active_users"]
weekly = (
df.resample("W-MON", on="date")
.agg(revenue=("revenue", "sum"),
users=("active_users", "mean"),
arpu=("arpu", "mean"),
churn=("churn_rate", "mean"))
.round(3)
)
print(weekly.tail())
Example 5: Five-year ROI scenario comparison
# Example 5: Five-year ROI scenario comparison -- Computational Methods Data Science Using Python
import numpy as np
scenarios = {
"conservative": {"cost": 250_000, "annual_return": 0.06},
"balanced": {"cost": 250_000, "annual_return": 0.09},
"aggressive": {"cost": 250_000, "annual_return": 0.13},
}
years = np.arange(1, 6)
for name, s in scenarios.items():
future_value = s["cost"] * (1 + s["annual_return"]) ** years
npv = future_value - s["cost"]
payback_year = int(np.argmax(future_value >= s["cost"] * 1.5)) + 1
print(f"{name:>12}: year-5 FV = ${future_value[-1]:>10,.0f} | "
f"NPV = ${npv[-1]:>10,.0f} | 1.5x payback ~ year {payback_year}")