Pandas DataFrames - Answer Key

Authors

Noor Sohail

Will Gammerdinger

Published

March 15, 2026

Exercise 1

  1. Use the tail() method to inspect our metadata DataFrame.
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

Exercise 2

  1. Retrieve the values of 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
  1. Retrieve the values of metadata where the value in the genotype is not equal to Wt.
# Retrieve the columns of metadata where genotype is not 'Wt'
metadata[metadata["genotype"] != 'Wt']
genotype celltype replicate
sample4 KO typeA 1
sample5 KO typeA 2
sample6 KO typeA 3
sample10 KO typeB 1
sample11 KO typeB 2
sample12 KO typeB 3

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.
# Summarize the number of times we observe each replicate in metadata
metadata["replicate"].value_counts()
replicate
1    4
2    4
3    4
Name: count, dtype: int64

Reuse

CC-BY-4.0