Skip to main content
Brave Programmer Logo

BraveProgrammer

BraveProgrammer

HomeProjectsBlogsCoursesLessonsAbout

Site footer

BraveProgrammer

Free coding courses, practical tutorials, and real projects from BraveProgrammer. Learn web development with React, Next.js, and TypeScript.

Navigation

  • Home
  • Projects
  • Blogs
  • Courses

Resources

  • About
  • Lessons
  • Teach on BraveProgrammer

© 2026 BraveProgrammer. All rights reserved.

Applying Functions: | Master Data Science with Python lesson | BraveProgrammer
  1. Courses
  2. /
  3. Master Data Science with Python

Lesson 29 of 60

·python

Applying Functions: `apply`, `map`, and Vectorized Operations

20 minutes

Course progress48%

Applying Functions in Pandas

Pandas allows you to apply custom Python logic across rows or columns.

Using map for element‑wise transformation

df['temp_f'] = df['temp_c'].map(lambda c: c * 9/5 + )
32

Using apply on a Series

df['name'] = df['name'].apply(str.title)

Using apply on a DataFrame (row‑wise)

def compute_score(row):
    return row['units'] * row['price'] * 0.9   # 10% discount

df['score'] = df.apply(compute_score, axis=1)

Vectorized operations (preferred when possible)

df['revenue'] = df['units'] * df['price']

Using transform for broadcasting results back to original shape

# Z‑score per group
zscore = df.groupby('store_id')['revenue'].transform(lambda x: (x - x.mean()) / x.std())
df['revenue_z'] = zscore

Info

Avoid apply on large DataFrames; vectorized alternatives are orders of magnitude faster.
Make it stickPractice what you've learned1 quiz · 4 practical tests · Optional activities from Master Data Science with PythonBrowse activities
Previous lessonCategorical Data and Encoding TechniquesContinue to lesson 30Pandas Project: Titanic Data AnalysisBack to Master Data Science with Python curriculum