Let’s compare applymap(), apply(), and map() side by side with code and output, so you see clearly when to use each.
Setup
Output:
1. applymap() → element-wise on the entire DataFrame
Output:
✅ Every value in every column was multiplied by 10.
2. apply() → column-wise or row-wise operations
-
By default (
axis=0), applies function to each column (Series).
Output:
-
With
axis=1, applies function to each row.
Output:
✅ Works on rows/columns as groups, not individual elements.
3. map() → element-wise, but only for a Series
Output:
✅ Applies only to one column (Series), not the entire DataFrame.
📌 Quick Summary
| Function | Scope | Usage Example |
|---|---|---|
applymap() |
Element-wise, all DataFrame | df.applymap(lambda x: x*2) |
apply() |
Row-wise / Column-wise | df.apply(sum, axis=0) |
map() |
Element-wise, Series only | df["col"].map(str.upper) |
👉 So, if you want element-wise over the whole DataFrame, use applymap().
👉 If you want row or column aggregations/transformations, use apply().
👉 If you want element-wise on a single column, use map().

浙公网安备 33010602011771号