How to run qPCR delta-delta Ct analysis in Python the right way
Compute qPCR delta-delta Ct fold changes in Python, run statistics on delta Ct, catch bad technical replicates, and download a verified notebook.
By Amir Hesham

Most qPCR spreadsheet templates break in two predictable places: someone runs a t-test directly on raw 2^-ddCt fold changes instead of dCt, and a single pipetting bubble in one technical triplicate drags the biological replicate down without anyone noticing. Fixing both takes less than 40 lines of Python, as long as your QC rules and housekeeping gene choice stay visible on screen.
Download the verified files for this recipe: qpcr_ct_results.csv (72 rows, SHA-256 116e614450ef) and qpcr_ddct_verified.ipynb (executed clean-start with zero errors).
Plain-English prompt walkthrough
Drop qpcr_ct_results.csv into a local Dalliance folder and start with one clear question:
Calculate IL6 fold change in Drug_X vs Control from
qpcr_ct_results.csvusing the delta-delta Ct method normalized to GAPDH, check technical replicate SD (>0.5 Ct), run statistics on delta Ct (not raw fold change), and compare normalizing to GAPDH vs ACTB.
Dalliance reads the 72-row plate table locally, sees four biological replicates per group (C1 to C4 in Control, T1 to T4 in Drug_X) measured in technical triplicate across three genes (IL6, GAPDH, and ACTB), and runs technical replicate QC before collapsing wells.
Right next to the output, Dalliance prints how it read your question and underlines every analytic choice as a clickable control. You can try clicking an underlined assumption yourself in the live demo on dalliance.io before downloading the app. In a qPCR workflow, clicking to toggle technical replicate QC or switching the reference gene from GAPDH to ACTB reruns the cell on the spot without rewriting formulas across Excel tabs.
Why statistics belong on delta Ct, not raw fold change
Ct values live on a base-2 logarithmic scale, where one cycle equals a two-fold change in starting template and experimental error is roughly symmetric. Once you convert ddCt to 2^-ddCt, the scale becomes asymmetric: a two-fold decrease spans 0.5 to 1.0, while a two-fold increase spans 1.0 to 2.0.
Running a parametric t-test on raw fold changes distorts both variance and p-values, especially when control replicates cluster tightly around 1.0 and treated replicates fan out across higher values. The cleaner statistical workflow computes per-sample dCt = Ct_target - Ct_reference for each biological replicate, runs Welch's t-test directly on those dCt values, and calculates the 95% confidence interval on mean_ddCt before back-transforming the point estimate and both bounds through 2^-x. Notice how the resulting fold-change confidence interval is naturally asymmetric on the linear axis.
The analytical forks that move your fold change
Cell 2 of qpcr_ddct_verified.ipynb scans every biological-replicate-by-gene triplicate for technical standard deviation above 0.5 Ct. It flags one triplicate immediately: Drug_X biological replicate T2, gene IL6, with a mean of 25.708 Ct, SD of 1.942 Ct, minimum 24.551, and maximum 27.95. That single late-amplifying well at 27.95 Ct sits more than three cycles above its twin wells.

Here is how technical QC filtering and housekeeping gene selection move the exact verified outputs in Cell 4:
| Reference gene | Technical QC filtered | Mean ddCt | Fold change | 95% CI low | 95% CI high | Welch t-test p (on dCt) |
|---|---|---|---|---|---|---|
| GAPDH | True | -2.211 | 4.63 | 4.09 | 5.24 | 1.48e-06 |
| GAPDH | False | -1.930 | 3.81 | 2.56 | 5.67 | 0.0059 |
| ACTB | True | -2.557 | 5.88 | 5.10 | 6.79 | 3.23e-07 |
Two lab realities jump right off that table:
- Skipping technical replicate QC hides a bad well in plain sight. Leaving the
27.95 Ctpipetting outlier insideT2drops the reportedIL6induction from4.63-folddown to3.81-fold, stretches the 95% CI from4.09 to 5.24out to2.56 to 5.67, and weakens the Welch p-value by more than three orders of magnitude, from1.48e-06to0.0059. - Housekeeping gene drift shifts effect size even after clean QC. Normalizing the exact same QC-filtered
IL6Ct values toACTBinstead ofGAPDHpushes the fold change from4.63-foldto5.88-fold(95% CI5.10to6.79,p = 3.23e-07). Whenever a drug treatment subtly perturbs one reference gene, showing both reference normalizations in your notebook protects you when a reviewer asks how you validated housekeeping stability.
For full transparency, here are the exact per-sample biological replicate values under the primary GAPDH QC-filtered path:
| Group | Biological replicate | IL6 Ct | GAPDH Ct | dCt | ddCt | Fold change |
|---|---|---|---|---|---|---|
| Control | C1 | 26.462 | 18.055 | 8.407 | 0.088 | 0.941 |
| Control | C2 | 26.817 | 18.540 | 8.276 | -0.043 | 1.030 |
| Control | C3 | 26.103 | 17.905 | 8.198 | -0.121 | 1.087 |
| Control | C4 | 26.670 | 18.275 | 8.395 | 0.076 | 0.949 |
| Drug_X | T1 | 24.337 | 18.379 | 5.958 | -2.361 | 5.138 |
| Drug_X | T2 | 24.586 | 18.484 | 6.103 | -2.217 | 4.648 |
| Drug_X | T3 | 24.108 | 18.051 | 6.057 | -2.262 | 4.798 |
| Drug_X | T4 | 24.724 | 18.407 | 6.317 | -2.002 | 4.006 |
Notice how cleanly T2 falls back in line (4.648-fold) once the single 27.95 Ct technical outlier is trimmed, matching T1 (5.138), T3 (4.798), and T4 (4.006).
Copyable Python code from the verified notebook
This is the exact QC and delta-delta Ct block executed in qpcr_ddct_verified.ipynb:
import hashlib
import numpy as np
import pandas as pd
from scipy import stats
csv_path = "qpcr_ct_results.csv"
sha = hashlib.sha256(open(csv_path, "rb").read()).hexdigest()[:12]
df = pd.read_csv(csv_path)
print(f"File: {csv_path} | Rows: {len(df)} | SHA-256: {sha}")
tech_qc = df.groupby(["group", "biological_replicate", "gene"])["ct_value"].agg(
["mean", "std", "min", "max"]
).reset_index()
print("Flagged technical replicate groups (SD > 0.5 Ct):")
print(tech_qc[tech_qc["std"] > 0.5].to_string(index=False))
def fmt_p(p):
return f"{p:.2e}" if p < 0.001 else f"{p:.4f}"
def run_ddct(data, ref_gene="GAPDH", drop_bad_tech=True):
d = data.copy()
if drop_bad_tech:
keep_idx = []
for _, grp in d.groupby(["biological_replicate", "gene"]):
if grp["ct_value"].std(ddof=1) > 0.5 and len(grp) >= 3:
med = grp["ct_value"].median()
worst = (grp["ct_value"] - med).abs().idxmax()
keep_idx.extend([i for i in grp.index if i != worst])
else:
keep_idx.extend(grp.index.tolist())
d = d.loc[keep_idx]
bio = d.groupby(["group", "biological_replicate", "gene"])["ct_value"].mean().unstack("gene").reset_index()
bio["dCt"] = bio["IL6"] - bio[ref_gene]
ctrl_mean_dCt = bio.loc[bio["group"] == "Control", "dCt"].mean()
bio["ddCt"] = bio["dCt"] - ctrl_mean_dCt
bio["fold_change"] = 2.0 ** (-bio["ddCt"])
c_dct = bio.loc[bio["group"] == "Control", "dCt"]
t_dct = bio.loc[bio["group"] == "Drug_X", "dCt"]
_, p_val = stats.ttest_ind(t_dct, c_dct, equal_var=False)
mean_ddct = t_dct.mean() - c_dct.mean()
se_ddct = np.sqrt(t_dct.var(ddof=1) / len(t_dct) + c_dct.var(ddof=1) / len(c_dct))
return bio, float(p_val), {
"ref_gene": ref_gene,
"qc_filtered": drop_bad_tech,
"mean_ddCt": round(mean_ddct, 3),
"fold_change": round(2.0 ** (-mean_ddct), 2),
"FC_95CI_low": round(2.0 ** (-(mean_ddct + 1.96 * se_ddct)), 2),
"FC_95CI_high": round(2.0 ** (-(mean_ddct - 1.96 * se_ddct)), 2),
"welch_t_p_on_dCt": fmt_p(float(p_val)),
}
bio_main, p_main, res_main = run_ddct(df, "GAPDH", True)
_, _, res_noqc = run_ddct(df, "GAPDH", False)
_, _, res_actb = run_ddct(df, "ACTB", True)
print(pd.DataFrame([res_main, res_noqc, res_actb]).to_string(index=False))
Notice that technical outlier trimming only drops the single well farthest from the triplicate median when SD > 0.5 Ct and at least three wells are present, keeping the biological sample intact instead of deleting the entire replicate. The full bar-and-dot plotting cell lives inside qpcr_ddct_verified.ipynb.
Clean-start Verify proof
Every output above comes from a clean-start run of qpcr_ddct_verified.ipynb on Python 3.14.7, numpy 2.5.5, pandas 3.1.1, scipy 1.18.1, and matplotlib 3.11.2, reading qpcr_ct_results.csv with SHA-256 prefix 116e614450ef.
In Dalliance, one-click Verify restarts Python, reruns every cell from top to bottom with zero AI calls, and flags any cell whose output changed. Every notebook saves as a standard .ipynb file on your Mac or Windows machine with pinned package versions, data file fingerprints, and zero desktop telemetry. Saved cells rerun locally forever with no credits or subscription required. Because Dalliance does not offer a HIPAA BAA today, use it for wet-lab, preclinical, genomics, biostatistics, and de-identified datasets.
Run your own qPCR plate export in Dalliance
Try this workflow on your next qPCR export with Dalliance Starter for $0, giving you 100 one-time credits on verified email sign-up, no credit card, and saved notebooks that rerun locally for free forever. When you want ongoing monthly capacity across models from 18+ providers, Pro Annual is $199/year with two months free, 1,000 credits per month, rollover up to a 2,000-credit cap, and a single Polar PDF invoice ready for lab or university reimbursement.