The apply() Function
The apply() function lets you apply custom functions to rows, columns, or individual elements.
Apply to Columns
Apply a function to each column:
Loading Pandas Playground...
Apply to Rows
Use axis=1 to apply across rows:
Loading Pandas Playground...
Lambda Functions
Use lambda for simple operations:
Loading Pandas Playground...
Apply with Multiple Arguments
Pass additional arguments to your function:
Loading Pandas Playground...
applymap() for Element-wise
Apply function to every element:
Loading Pandas Playground...
Apply vs Vectorized Operations
Vectorized operations are usually faster:
Loading Pandas Playground...
Exercise: Custom Calculation
Loading Exercise...
Exercise: Transform Values
Loading Exercise...
Key Points
apply(func)applies function to columns (axis=0)apply(func, axis=1)applies to rows- Lambda functions for simple transformations
- Pass extra args via lambda or using
args= - Vectorized operations are faster when possible
- Use apply when you need complex logic
التالي · الدرس 16 من 42
String Methods
قراءة 1 دقيقة
أنهيت 15 من 42 درسًا

اسأل Byte عن هذا الدرس
محادثة خاصة حول هذا الدرس. قرأ Byte الدرس كاملًا، ويجيب خلال ثوانٍ، ويُظهر القسم الذي تأتي منه كل إجابة. يمكنك السؤال بأي لغة.
الأسئلة والأجوبة
أسئلة عامة حول هذا الدرس. يجيب AI Tutor فورًا بلغتك، ويراجع فريق FreeAcademy الإجابات، ويمكن لكل المتعلمين قراءتها.

