Skip to learning content

DATA SCIENCE PYTHON PLAYGROUND

Data Foundations · A little practice goes a long way.

← Inspect lessonsTINY TABLES · REAL PYTHON · YOUR PACE
Getting oriented · IR1 · 12 MIN

Review · First contact

Task 1 · Retrieve and combine

Exercises within this concept

  1. Task 1Retrieve and combineCurrent exercise
  2. Task 2Retrieve and combine
  3. Task 3Retrieve and combine
  4. Task 4Retrieve and combine
Task 1 · Pet adoption

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

  1. Display a reproducible sample of three rows using random_state=1.

Your inputs

Pet adoption · 6 synthetic rows
namespeciesageweightroom
MiloCat34.2A
PepperDog718.5B
LunaCat23.6A
BeanRabbit42.4B
RexDog522A
NoriRabbit11.8B

Revisit the concept lesson →

Remember the idea

Concept sketch: head(2): first two complete rowsnamepricescoreA28B46C39head(2): first two complete rows

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.

What each choice does
Code or choiceMeaning
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)
Your task · Task 1
  1. A spot check should include rows from anywhere in df.
  2. Display a reproducible sample of three rows using random_state=1.

Tab: indent · Shift+Tab: outdent · Esc, then Tab: leave editor

Edit Python. Control or Command plus Enter runs it. Tab indents by four spaces. Shift plus Tab outdents. Press Escape, then Tab or Shift plus Tab to leave the editor.

Each run executes all editor code in a fresh Python session. Display a value by leaving it on the final line.

Python starts when you open a lesson.

Output

Run your code to see what Python returns.