apply works on a row / column basis of a DataFrame
applymap works element-wise on a DataFrame
map works element-wise on a Series


Straight from Wes McKinney's Python for Data Analysis book, pg. 132 (I highly recommended this book):

Another frequent operation is applying a function on 1D arrays to each column or row. DataFrame’s apply method does exactly this:

In [116]: frame = DataFrame(np.random.randn(4, 3), columns=list('bde'), index=['Utah', 'Ohio', 'Texas', 'Oregon'])

In [117]: frame
Out[117]: 
               b         d         e
Utah   -0.029638  1.081563  1.280300
Ohio    0.647747  0.831136 -1.549481
Texas   0.513416 -0.884417  0.195343
Oregon -0.485454 -0.477388 -0.309548

In [118]: f = lambda x: x.max() - x.min()

In [119]: frame.apply(f)
Out[119]: 
b    1.133201
d    1.965980
e    2.829781
dtype: float64

Many of the most common array statistics (like sum and mean) are DataFrame methods, so using apply is not necessary.

Element-wise Python functions can be used, too. Suppose you wanted to compute a formatted string from each floating point value in frame. You can do this with applymap:

In [120]: format = lambda x: '%.2f' % x

In [121]: frame.applymap(format)
Out[121]: 
            b      d      e
Utah    -0.03   1.08   1.28
Ohio     0.65   0.83  -1.55
Texas    0.51  -0.88   0.20
Oregon  -0.49  -0.48  -0.31

The reason for the name applymap is that Series has a map method for applying an element-wise function:

In [122]: frame['e'].map(format)
Out[122]: 
Utah       1.28
Ohio      -1.55
Texas      0.20
Oregon    -0.31
Name: e, dtype: object
Answer from jeremiahbuddha on Stack Overflow
Top answer
1 of 12
755

apply works on a row / column basis of a DataFrame
applymap works element-wise on a DataFrame
map works element-wise on a Series


Straight from Wes McKinney's Python for Data Analysis book, pg. 132 (I highly recommended this book):

Another frequent operation is applying a function on 1D arrays to each column or row. DataFrame’s apply method does exactly this:

In [116]: frame = DataFrame(np.random.randn(4, 3), columns=list('bde'), index=['Utah', 'Ohio', 'Texas', 'Oregon'])

In [117]: frame
Out[117]: 
               b         d         e
Utah   -0.029638  1.081563  1.280300
Ohio    0.647747  0.831136 -1.549481
Texas   0.513416 -0.884417  0.195343
Oregon -0.485454 -0.477388 -0.309548

In [118]: f = lambda x: x.max() - x.min()

In [119]: frame.apply(f)
Out[119]: 
b    1.133201
d    1.965980
e    2.829781
dtype: float64

Many of the most common array statistics (like sum and mean) are DataFrame methods, so using apply is not necessary.

Element-wise Python functions can be used, too. Suppose you wanted to compute a formatted string from each floating point value in frame. You can do this with applymap:

In [120]: format = lambda x: '%.2f' % x

In [121]: frame.applymap(format)
Out[121]: 
            b      d      e
Utah    -0.03   1.08   1.28
Ohio     0.65   0.83  -1.55
Texas    0.51  -0.88   0.20
Oregon  -0.49  -0.48  -0.31

The reason for the name applymap is that Series has a map method for applying an element-wise function:

In [122]: frame['e'].map(format)
Out[122]: 
Utah       1.28
Ohio      -1.55
Texas      0.20
Oregon    -0.31
Name: e, dtype: object
2 of 12
373

Comparing map, applymap and apply: Context Matters

The major differences are:

Definition

  • map is defined on Series only
  • applymap is defined on DataFrames only
  • apply is defined on both

Input argument

  • map accepts dict, Series, or callable
  • applymap and apply accept callable only

Behavior

  • map is elementwise for Series
  • applymap is elementwise for DataFrames
  • apply also works elementwise but is suited to more complex operations and aggregation. The behaviour and return value depends on the function.

Use case (the most important difference)

  • map is meant for mapping values from one domain to another, so is optimised for performance, e.g.,

    df['A'].map({1:'a', 2:'b', 3:'c'})
    
  • applymap is good for elementwise transformations across multiple rows/columns, e.g.,

    df[['A', 'B', 'C']].applymap(str.strip)
    
  • apply is for applying any function that cannot be vectorised, e.g.,

    df['sentences'].apply(nltk.sent_tokenize)
    

Also see When should I (not) want to use pandas apply() in my code? for a writeup I made a while back on the most appropriate scenarios for using apply. (Note that there aren't many, but there are a few— apply is generally slow.)


Summarising

map applymap apply
Defined on Series? Yes No Yes
Defined on DataFrame? No Yes Yes
Argument dict, Series, or callable1 callable2 callable
Elementwise? Yes Yes Yes
Aggregation? No No Yes
Use Case Transformation/mapping3 Transformation More complex functions
Returns Series DataFrame scalar, Series, or DataFrame4

Footnotes

  1. map when passed a dictionary/Series will map elements based on the keys in that dictionary/Series. Missing values will be recorded as NaN in the output.

  2. applymap in more recent versions has been optimised for some operations. You will find applymap slightly faster than apply in some cases. My suggestion is to test them both and use whatever works better.

  3. map is optimised for elementwise mappings and transformation. Operations that involve dictionaries or Series will enable pandas to use faster code paths for better performance.

  4. Series.apply returns a scalar for aggregating operations, Series otherwise. Similarly for DataFrame.apply. Note that apply also has fastpaths when called with certain NumPy functions such as mean, sum, etc.

🌐
GeeksforGeeks
geeksforgeeks.org › python › difference-between-map-applymap-and-apply-methods-in-pandas
Difference between Map, Applymap and Apply Methods in Pandas - GeeksforGeeks
February 9, 2026 - In recent Pandas versions, map() works on both Series and DataFrame, making it a unified alternative for element-wise operations. When used with a DataFrame, map() applies the given function to each individual element, similar to the earlier applymap() method.
🌐
Medium
medium.com › @amit25173 › pandas-map-vs-apply-practical-guide-51f046a15cd9
pandas map vs apply (Practical Guide) | by Amit Yadav | Medium
March 6, 2025 - You need to apply a function across multiple columns or rows. You need row-wise operations, where each row’s values are used together. ... Let’s say you have a DataFrame with numbers and you want to double them.
🌐
Towards Data Science
towardsdatascience.com › home › latest › pandas: apply, map or transform?
Pandas: apply, map or transform? | Towards Data Science
January 23, 2025 - The na_action essentially lets you decide what happens to NaN values if they exist in the series. When set to "ignore" , arg won’t be applied to NaN values. For eg, if you wanted to replace categorical values in your series using a mapping, you could do something like this:
🌐
Kaggle
kaggle.com › general › 516360
Speed of for-loop vs apply() vs map()
Checking your browser before accessing www.kaggle.com · Click here if you are not automatically redirected after 5 seconds
🌐
Medium
medium.com › @ayeshasidhikha188 › apply-map-applymap-functions-in-pandas-d39b17655278
Apply, Map, ApplyMap -Functions in Pandas | by Ayesha sidhikha | Medium
February 4, 2025 - To change any one row into upper case, we operate on the index level. We can also use apply() on the entire dataframe. ... map() can only operate on series and not on whole dataframes.
🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.DataFrame.map.html
pandas.DataFrame.map — pandas 3.0.2 documentation
Apply a function elementwise on a Series. ... >>> df_copy = df.copy() >>> df_copy.iloc[0, 0] = pd.NA >>> df_copy.map(lambda x: len(str(x)), na_action="ignore") 0 1 0 NaN 4 1 5.0 5
Find elsewhere
🌐
Towards Data Science
towardsdatascience.com › home › latest › apply() vs map() vs applymap() in pandas
apply() vs map() vs applymap() in Pandas | Towards Data Science
January 16, 2025 - First, let’s create an example DataFrame that we will use throughout this article in order to demonstrate a few concepts that will help us highlight the difference between apply(), map() and applymap(). ... df = pd.DataFrame( [ (1, 521, True, 10.1, 'Hello'), (2, 723, False, 54.2, 'Hey'), (3, 123, False, 33.2, 'Howdy'), (4, 641, True, 48.6, 'Hi'), (5, 467, False, 98.1, 'Hey'), ], columns=['colA', 'colB', 'colC', 'colD', 'colE'] ) print(df) colA colB colC colD colE 0 1 521 True 10.1 Hello 1 2 723 False 54.2 Hey 2 3 123 False 33.2 Howdy 3 4 641 True 48.6 Hi 4 5 467 False 98.1 Hey · [pandas.DataFrame.apply](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.apply.html) method is used to apply a function along the specified axis of the pandas DataFrame.
🌐
Spark By {Examples}
sparkbyexamples.com › home › pandas › pandas difference between map, applymap and apply methods
Pandas Difference Between map, applymap and apply Methods - Spark By {Examples}
March 27, 2024 - What is the difference between map(), applymap() and apply() methods in pandas? - In padas, all these methods are used to perform either to modify the
🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.Series.map.html
pandas.Series.map — pandas 3.0.2 documentation
Apply a function elementwise on a whole DataFrame. ... When arg is a dictionary, values in Series that are not in the dictionary (as keys) are converted to NaN. However, if the dictionary is a dict subclass that defines __missing__ (i.e. provides a method for default values), then this default is used rather than NaN. ... map accepts a dict or a Series.
🌐
Medium
medium.com › @vivekmcm1 › a-guide-to-applying-functions-in-pandas-apply-map-and-applymap-54165aa509f8
A Guide to Applying Functions in Pandas: apply(), map(), and applymap() | by Vivek | Medium
January 6, 2025 - map(): This method is for Series only and is useful for elementwise transformations or mapping values based on a dictionary. applymap(): Use applymap() when you need to apply a function elementwise across all the values in a DataFrame.
Top answer
1 of 4
18

Different use cases. When comparing them, it is useful to bring up apply and agg as well.

Setup

np.random.seed([3,1415])
df = pd.DataFrame(np.random.randint(10, size=(6, 4)), columns=list('ABCD'))

df

   A  B  C  D
0  0  2  7  3
1  8  7  0  6
2  8  6  0  2
3  0  4  9  7
4  3  2  4  3
5  3  6  7  7

pd.DataFrame.applymap
This takes a function and returns a new dataframe with the results of that function being applied to the value in each cell and replacing the value of the cell with the result.

df.applymap(lambda x: str(x) * x)

          A        B          C        D
0                 22    7777777      333
1  88888888  7777777              666666
2  88888888   666666                  22
3               4444  999999999  7777777
4       333       22       4444      333
5       333   666666    7777777  7777777

pd.DataFrame.agg
Takes one or more functions. Each function is expected to be an aggregation function. Meaning each function is applied to each column and is expected to return a single value that replaces the entire column. Examples would be 'mean' or 'max'. Both of those take a set of data and return a scalar.

df.agg('mean')

A    3.666667
B    4.500000
C    4.500000
D    4.666667
dtype: float64

Or

df.agg(['mean', 'std', 'first', 'min'])

             A         B         C         D
mean  3.666667  4.500000  4.500000  4.666667
std   3.614784  2.167948  3.834058  2.250926
min   0.000000  2.000000  0.000000  2.000000

pd.DataFrame.transform
Takes one function that is expected to be applied to a column and return a column of equal size.

df.transform(lambda x: x / x.std())

          A         B         C         D
0  0.000000  0.922531  1.825742  1.332785
1  2.213133  3.228859  0.000000  2.665570
2  2.213133  2.767594  0.000000  0.888523
3  0.000000  1.845062  2.347382  3.109832
4  0.829925  0.922531  1.043281  1.332785
5  0.829925  2.767594  1.825742  3.109832

pd.DataFrame.apply
pandas attempts to figure out if apply is reducing the dimensionality of the column it was operating on (aka, aggregation) or if it is transforming the column into another column of equal size. When it figures it out, it runs the remainder of the operation as if it were an aggregation or transform procedure.

df.apply('mean')

A    3.666667
B    4.500000
C    4.500000
D    4.666667
dtype: float64

Or

df.apply(lambda x: (x - x.mean()) / x.std())

          A         B         C         D
0 -1.014353 -1.153164  0.652051 -0.740436
1  1.198781  1.153164 -1.173691  0.592349
2  1.198781  0.691898 -1.173691 -1.184698
3 -1.014353 -0.230633  1.173691  1.036611
4 -0.184428 -1.153164 -0.130410 -0.740436
5 -0.184428  0.691898  0.652051  1.036611
2 of 4
7

What's meant by .transform() returns a like-indexed DataFrame stated in the documentation?

That means .transform() applies a function to every value (or a group, once preceded by groupby) in the DataFrame and returns another DataFrame with the same length as the input, so to emphasize: it keeps the input index labels in the output.

Is there any use case where one of applymap/transform and the other doesn't?

Sure. Here are some examples:

1) applymap Vs transform

Since applymap performs on all elements of a DataFrame, you can't perform applymap on a Series:

df['Quantity'].transform(lambda x: x+10) # successful
df['Quantity'].apply(lambda x: x+10) # successful
df['Quantity'].applymap(lambda x: x+10) # gives AttributeError: 'Series' object has no attribute 'applymap'

# unless you cast it to DataFrame:
pd.DataFrame(df['Quantity']).applymap(lambda x: x+10) # successful

Another important difference is that despite .applymap() which operates element-wise, .transform() can perform group-wise operations, referred to in the next part.

Moreover, applymap cannot be preceded by groupby.

2) apply Vs transform

apply and transform can be interchangeable as long as you perform them on DataFrame column(s). Here is a simple example:

# imagine the following DataFrame
df = pd.DataFrame({'Label': ['A', 'B', 'C', 'A', 'C'],
                   'Values': [0,1,2,3,4],
                   'Quantity': [5,6,7,8,9]}, index = list('VWXYZ'))


    Label   Quantity   Values
---------------------------------
V    A         5         0
W    B         6         1
X    C         7         2
Y    A         8         3
Z    C         9         4


df.loc[:, ['Quantity', 'Values']].apply(lambda x: x+10)
df.loc[:, ['Quantity', 'Values']].transform(lambda x: x+10)
# both of them give the following same result:

    Quantity   Values
-------------------------
V    15          10
W    16          11
X    17          12
Y    18          13
Z    19          14

The main difference emerges once they follow a groupby operation. For instance:

label_grouping = df.groupby('Label')
label_grouping.apply(lambda x: x.mean())
# output:

      Quantity   Values
Label
-----------------------
A       6.5       1.5
B       6.0       1.0
C       8.0       3.0

label_grouping.transform(lambda x: x.mean())
# see how `transform` could manage to keeps the input index labels in the output
# output:

    Quantity   Values
------------------------
V     6.5       1.5
W     6.0       1.0
X     8.0       3.0
Y     6.5       1.5
Z     8.0       3.0

The above example clearly shows how transform can retain input DataFrame indexes; So to get the better of this exclusive feature, the following short example tries to clarify how to benefit from this alignment of the indexes between the input and output of the transform operation, by calculating the percentage of order total that each product represents:

df_sales = pd.DataFrame({'OrderID': [1001,1001,1001,1002,1002],
                         'Product': ['p1','p2','p3','p1','p4'],
                         'Quantity': [30,20,70,160,40]})


    OrderID   Product   Quantity
-----------------------------------
0    1001       p1        30
1    1001       p2        20
2    1001       p3        70
3    1002       p1        160
4    1002       p4        40


df_sales['total_per_order'] = df_sales.groupby(['OrderID'])['Quantity'].transform(lambda x: x.sum()) 
df_sales['pct_of_order'] = df_sales['Quantity'] / df_sales['total_per_order']


    OrderID   Product   Quantity   total_per_order   pct_of_order
----------------------------------------------------------------------
0    1001       p1        30           120             0.250000
1    1001       p2        20           120             0.166667
2    1001       p3        70           120             0.583333
3    1002       p1        160          200             0.800000
4    1002       p4        40           200             0.200000

It's highly advised to follow this link for a more detailed example: https://pbpython.com/pandas_transform.html

Many aggregation functions are built in directly to the groupby object to save you some typing. specifically some of the common ones to benefit from are (prefixed by gb):

  • gb.apply
  • gb.transform
  • gb.filter
  • gb.agg
  • gb.count
  • gb.comsum
  • gb.fillna
  • ...

Hope this helped :)

🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.DataFrame.applymap.html
pandas.DataFrame.applymap — pandas 2.3.3 documentation
Deprecated since version 2.1.0: DataFrame.applymap has been deprecated. Use DataFrame.map instead.
🌐
Studymachinelearning
studymachinelearning.com › pandas-applymap
Pandas – Applymap – Study Machine Learning
The main difference between apply() and applymap() method is: Pandas’ apply() method work on row/column basis of a DataFrame.
🌐
Research Software Engineering Sheffield
rse.shef.ac.uk › pando-python › optimisation-minimise-python.html
Performance Profiling & Optimisation (Python): Understanding Python (NumPy/Pandas)
March 10, 2025 - Pandas allows it’s own methods to be applied to rows in many cases by passing axis=1, where available these functions should be preferred over manual loops. Where you can’t find a suitable method, apply() can be used, which is similar to map()/vectorize(), to apply your own function to rows.
🌐
Kaggle
kaggle.com › code › alexgazagnes › fastest-list-compr-map-vs-pandas-apply-map
Fastest : list compr./map vs pandas apply/ map ?
Checking your browser before accessing www.kaggle.com · Click here if you are not automatically redirected after 5 seconds
🌐
Spark By {Examples}
sparkbyexamples.com › home › pandas › pandas apply map (applymap()) explained
Pandas apply map (applymap()) Explained - Spark By {Examples}
December 9, 2024 - The very basic level difference between the pandas apply map, apply(), and map() function is that, applymap is defined on DataFrames, map() is defined on Series while df.apply() work on both.