A spot check should include rows from anywhere in df.
The editable setup on the right creates df. Run executes the setup and your work from top to bottom.
Your requirements
- Display a reproducible sample of three rows using random_state=1.
Your inputs
| name | species | age | weight | room |
|---|---|---|---|---|
| Milo | Cat | 3 | 4.2 | A |
| Pepper | Dog | 7 | 18.5 | B |
| Luna | Cat | 2 | 3.6 | A |
| Bean | Rabbit | 4 | 2.4 | B |
| Rex | Dog | 5 | 22 | A |
| Nori | Rabbit | 1 | 1.8 | B |
Remember the idea
A preview returns selected rows with all their columns. It leaves the original table unchanged.
A small example
For rows A, B, C, D: head(2) shows A, B; tail(2) shows C, D.
| Code or choice | Meaning |
|---|---|
head(n) / tail(n) | Take n rows from the start / end. With no number, each defaults to five. |
sample(n, random_state=1) | Choose n rows from across the table. The fixed seed repeats the selection on the same data. |
Hint
A reproducible sample needs both a sample size and a random seed.
Reveal solution
One way to do it. Keep any supplied setup in the editor and use this in the Your work section.
df.sample(3, random_state=1)