Skip to content
Learn Netverks

Lesson

Step 15/36 42% through track

apply-map-replace

Apply, map, and replace

Last reviewed May 28, 2026 Content v20260528
Track mode
server_script
Means
Server runner
Reading
~1 min
Level
intermediate

This lesson

This lesson teaches Apply, map, and replace: Pandas tabular manipulation—indexing, dtypes, reshaping, and analysis habits for real-world tables.

Teams apply Apply, map, and replace in every serious Pandas project—skipping it leaves blind spots in analysis and reviews.

You will apply Apply, map, and replace in contexts like: CSV/Parquet analysis, ETL notebooks, and ad hoc reporting.

Read the narrative, run `import pandas as pd` snippets with in-memory DataFrames (install pandas and numpy with pip if needed), inspect `.head()`, `.dtypes`, and complete MCQs.

When you can explain the previous lesson's ideas in your own words.

Use map for dict/Series lookups on a Series, replace for value substitution, and apply when you need row-wise or column-wise custom logic—know that apply is often slower than vectorization.

map on Series

import pandas as pd
grades = pd.Series(['A', 'B', 'C'])
points = grades.map({'A': 4, 'B': 3, 'C': 2})
print(points)

replace

df = pd.DataFrame({'status': ['ok', 'err', 'ok']})
df['status'] = df['status'].replace({'err': 'error'})
print(df)

apply axis

  • df['col'].apply(func) — element-wise on Series
  • df.apply(func, axis=0) — per column
  • df.apply(func, axis=1) — per row (slower; use sparingly)

Important interview questions and answers

  1. Q: map vs apply on Series?
    A: map expects dict-like lookup; apply calls func on each value—more general, often slower.
  2. Q: When apply is OK?
    A: Complex row logic that cannot be vectorized; small DataFrames; prototyping.

Self-check

  1. Map letter grades to numeric points.
  2. Replace a sentinel value across a column.

Tip: Use map for dict lookups; reserve apply for logic that cannot vectorize.

Interview prep

map vs apply?

map for dict lookup; apply more general but slower per element.

replace?

Substitute known values across column—good for cleaning codes.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Playground

Runs on the configured server runner (dev: npm run runner with LEARNING_RUNNER_ENABLED=true). Output appears below the editor.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • Avoid row apply?
  • map dict use?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump