metadata.tail()| genotype | celltype | replicate | |
|---|---|---|---|
| sample8 | Wt | typeB | 2 |
| sample9 | Wt | typeB | 3 |
| sample10 | KO | typeB | 1 |
| sample11 | KO | typeB | 2 |
| sample12 | KO | typeB | 3 |
Pandas DataFrames - Answer KeyNoor Sohail
Will Gammerdinger
March 15, 2026
tail() method to inspect our metadata DataFrame.metadata where the value in the replicate is column is two or greater.# Retrieve the columns of metadata where replicate is 2 or greater
metadata[metadata["replicate"] >= 2]| genotype | celltype | replicate | |
|---|---|---|---|
| sample2 | Wt | typeA | 2 |
| sample3 | Wt | typeA | 3 |
| sample5 | KO | typeA | 2 |
| sample6 | KO | typeA | 3 |
| sample8 | Wt | typeB | 2 |
| sample9 | Wt | typeB | 3 |
| sample11 | KO | typeB | 2 |
| sample12 | KO | typeB | 3 |
metadata where the value in the genotype is not equal to Wt.value_counts() method to summarize the number of times you observe each replicate number in the replicate column of metadata.---
title: "`Pandas` DataFrames - Answer Key"
author:
- Noor Sohail
- Will Gammerdinger
date: "2026-03-15"
license: "CC-BY-4.0"
editor_options:
markdown:
wrap: 72
jupyter: intro_python
---
```{python}
#| label: load_libraries_data_py
#| echo: false
# Load libraries and data
import pandas as pd
metadata = pd.read_csv("data/mouse_exp_design.csv")
```
# Exercise 1
1. Use the `tail()` method to inspect our `metadata` DataFrame.
```{python}
#| label: exercise_1
metadata.tail()
```
# Exercise 2
1. Retrieve the values of `metadata` where the value in the `replicate` is column is two or greater.
```{python}
#| label: metadata_replicate
# Retrieve the columns of metadata where replicate is 2 or greater
metadata[metadata["replicate"] >= 2]
```
2. Retrieve the values of `metadata` where the value in the `genotype` is not equal to `Wt`.
```{python}
#| label: metadata_genotype
# Retrieve the columns of metadata where genotype is not 'Wt'
metadata[metadata["genotype"] != 'Wt']
```
# Exercise 3
1. Use the `value_counts()` method to summarize the number of times you observe each replicate number in the `replicate` column of `metadata`.
```{python}
#| label: value_counts
# Summarize the number of times we observe each replicate in metadata
metadata["replicate"].value_counts()
```