Skip to learning content

DATA SCIENCE PYTHON PLAYGROUND

Data Foundations · A little practice goes a long way.

← Wrangle / Preprocess lessonsTINY TABLES · REAL PYTHON · YOUR PACE
Types, dates & missingness · WR2 · 12 MIN

Bridge review · Sections 02 + 03

Task 1 · Section 02 · W07: create a numeric column

Exercises within this concept

  1. Task 1Section 02 · W07: create a numeric columnCurrent exercise
  2. Task 2Section 02 · W10: clean text
  3. Task 3Section 03 · W12: convert numeric text
Task 1 · Pet adoption

Add age_months to df from age in years (12 months per year).

The editable setup on the right creates df. Run executes the setup and your work from top to bottom.

Your requirements

  1. Keep the original age values and all other columns; display df.

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: doubled = price × 2, on each rowpricedoubled244836doubled = price × 2, on each row

Arithmetic on columns works row by row. Assigning to a new column name stores a derived measurement alongside the originals.

A small example

Prices [3, 5] plus tips [1, 2] give totals [4, 7]. Ages [2, 3] years become [24, 36] months.

What each choice does
Code or choiceMeaning
df["new"] = column * numberApply the same multiplier to every value.
df["new"] = first + secondCombine matching row values; use compatible units.
Hint

A unit conversion belongs in a new, clearly named column.

Reveal solution

One way to do it. Keep any supplied setup in the editor and use this in the Your work section.

df["age_months"] = df["age"] * 12
df
Your task · Task 1
  1. Add age_months to df from age in years (12 months per year).
  2. Keep the original age values and all other columns; display df.

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.