Before you start
You can fetch records from NCBI (lesson 4) and run Python. In Colab, run !pip install biopython pandas first.
Learning objectives
By the end of this lesson you will be able to: build and inspect a pandas DataFrame, select rows and columns and filter your data, read real tabular files into a DataFrame, and summarise a table to answer a question.
The DataFrame: a spreadsheet in Python
Pandas' core object is the DataFrame - a table with named columns and rows. If you've used Excel or the R lesson, this will feel familiar.
import pandas as pd genes = pd.DataFrame({ "gene": ["TP53", "BRCA1", "EGFR", "MYC"], "length": [25800, 81200, 192600, 7500], # approximate gene lengths in bp (rounded) "chrom": ["17", "17", "7", "8"], }) genes.head() # preview the first rows genes["length"] # pull out one column
The moves you'll use constantly
# 1. FILTER rows by a condition big = genes[genes["length"] > 10000] # 2. SORT (sorting returns a new table, so save it to a name) genes_sorted = genes.sort_values("length", ascending=False) # 3. a new COLUMN computed from others genes["length_kb"] = genes["length"] / 1000 # 4. SUMMARIZE - overall and per group print(genes["length"].mean()) genes.groupby("chrom")["length"].mean() # average length per chromosome
Why pandas is worth learning once
Filter, sort, compute, group, summarize - these five verbs answer most questions you'll ever ask of a data table, whether it's 4 genes or 40,000. Two more you'll use all the time: df.describe() gives count, mean, min and max for every numeric column in one go, and pd.merge(table_a, table_b, on="gene") joins two tables that share a column (the next lesson covers merging in detail). Learn them here and they pay off in every later track, including the RNA-seq results table.
Reading real files
Real data usually arrives as a CSV. One line loads it:
df = pd.read_csv("my_data.csv") df.info() # columns, types, and missing values at a glance
Fetch & summarize real genes
Time to combine everything in Track 1: pull real gene sequences from NCBI, then use pandas to build a clean summary table comparing them. This is your portfolio-ready deliverable.
โถ Build it in a notebook
Run !pip install biopython pandas first.
1Fetch three real genes
from Bio import Entrez, SeqIO import pandas as pd Entrez.email = "your.email@example.com" accessions = { "insulin": "NM_000207", "beta-globin": "NM_000518", "APP": "NM_000484", } seqs = {} for name, acc in accessions.items(): h = Entrez.efetch(db="nucleotide", id=acc, rettype="fasta", retmode="text") seqs[name] = str(SeqIO.read(h, "fasta").seq) h.close()
2Summarize with pandas
rows = [] for name, seq in seqs.items(): n = len(seq) gc = (seq.count("G") + seq.count("C")) / n * 100 rows.append({ "gene": name, "length": n, "GC_percent": round(gc, 1), "A": seq.count("A"), "C": seq.count("C"), "G": seq.count("G"), "T": seq.count("T"), }) df = pd.DataFrame(rows) df
3Ask questions of your table
df = df.sort_values("GC_percent", ascending=False) # most GC-rich first print(df) print("Mean GC%:", round(df["GC_percent"].mean(), 1)) print("Longest mRNA:", df.loc[df["length"].idxmax(), "gene"]) # save your summary - your deliverable df.to_csv("gene_summary.csv", index=False)
4Visualize it
import matplotlib.pyplot as plt df.plot(x="gene", y="GC_percent", kind="bar", legend=False, color="#5b9cf8", title="GC content by gene") plt.ylabel("GC %"); plt.tight_layout(); plt.show()
seqs dictionary instead of fetching - every step from #2 onward works identically.๐ You've finished Track 1!
You can now read sequence files, recognize every major format, manipulate sequences with Biopython, pull real data from public databases, and summarize it with pandas - and you built a portfolio-ready gene summary to prove it.
Put it on your portfolio. Save the notebook and gene_summary.csv to a GitHub repo with a short README explaining what it does. That's a real, shareable piece of work - exactly what the reproducibility-and-career track will help you polish.
The fetch printed a warning - did it fail?
Warnings (like Biopython reminding you to set an email) aren't errors - the code still produced your table. Read the message, but if you got a DataFrame at the end, it worked.
Check your understanding
Sources & further reading
- Ziemann M, Eren Y, El-Osta A. Gene name errors are widespread in the scientific literature. Genome Biology 17: 177, 2016. (why code beats spreadsheets for gene tables) doi:10.1186/s13059-016-1044-7
- O'Leary NA, Wright MW, Brister JR, et al. Reference sequence (RefSeq) database at NCBI: current status, taxonomic expansion, and functional annotation. Nucleic Acids Research 44: D733-D745, 2016. (the NM_ records in the project) doi:10.1093/nar/gkv1189
pandas itself: McKinney W. Data structures for statistical computing in Python. Proceedings of the 9th Python in Science Conference, 56-61, 2010. doi:10.25080/Majora-92bf1922-00a.
Last reviewed: October 2026.
