Difference between map, applymap and apply methods in Pandas
Last Updated :
11 Jul, 2025
Pandas library is extensively used for data manipulation and analysis. map(), applymap(), and apply() methods are methods of Pandas library in Python. The type of Output totally depends on the type of function used as an argument with the given method.
What is Pandas apply() method
The apply() method can be applied both to series and Dataframes where a function can be applied to both series and individual elements based on the type of function provided.
Syntax: s.apply(func, convert_dtype=True, args=())
Pandas DataFrame apply() Method
This method can be used on both a pandas Dataframe and series. The function passed as an argument typically works on rows/columns. The code below illustrates how apply() method works on Pandas Dataframe.
Python3
# Importing pandas library with an alias pd
import pandas as pd
# Dataframe generation
gfg_string = 'geeksforgeeks'
gfg_list = 5 * [pd.Series(list(gfg_string))]
gfg_df = pd.DataFrame(data = gfg_list)
print("Original dataframe:\n" + \
gfg_df.to_string(index = False,
header = False), end = '\n\n')
# Using apply method for sorting
# rows of characters present in
# the original dataframe
new_gfg_df = gfg_df.apply(lambda x:x.sort_values(), axis = 1)
print("Transformed dataframe:\n" + \
new_gfg_df.to_string(index = False,
header = False), end = '\n\n')
Output:
Pandas Series apply() Method
The below Code illustrates how to apply() method to the Pandas series:
Python3
# Importing pandas library with an alias pd
import pandas as pd
# Series generation
gfg_string = 'geeksforgeeks'
gfg_series = pd.Series(list(gfg_string))
print("Original series\n" +
gfg_series.to_string(index=False,
header=False), end='\n\n')
# Using apply method for converting characters
# present in the original series
new_gfg_series = gfg_series.apply(str.upper)
print("Transformed series:\n" +
new_gfg_series.to_string(index=False,
header=False), end='\n\n')
Output:
What is Pandas applymap() method
The applymap() method only works on a pandas Dataframe where a function is applied to every element individually. The function passed as an argument typically works on elements of the Dataframe applymap() and is typically used for elementwise operations.
Python3
# The code below illustrates how applymap
# method works on pandas Dataframe:
# Importing pandas
import pandas as pd
# DataFrame generation
gfg_string = 'geeksforgeeks'
gfg_list = 5 * [pd.Series(list(gfg_string))]
gfg_df = pd.DataFrame(data=gfg_list)
print("Original dataframe:\n" +
gfg_df.to_string(index=False,
header=False), end='\n\n')
# Using applymap method for transforming
# characters into uppercase characters
# present in the original dataframe
new_gfg_df = gfg_df.applymap(str.upper)
print("Transformed dataframe:\n" +
new_gfg_df.to_string(index=False,
header=False), end='\n\n')
Output:
What is Pandas map() method
The map() method only works on a pandas series where the type of operation to be applied depends on the argument passed as a function, dictionary, or list. This method is generally used to map values from two series having one column the same.
Python3
# The code below illustrates how the
# map method works on the Pandas series:
# Importing pandas
import pandas as pd
# Series generation
gfg_string = 'geeksforgeeks'
gfg_series = pd.Series(list(gfg_string))
print("Original series\n" +
gfg_series.to_string(index=False,
header=False), end='\n\n')
# Using apply method for converting characters
# present in the original series
new_gfg_series = gfg_series.map(str.upper)
print("Transformed series:\n" +
new_gfg_series.to_string(index=False,
header=False), end='\n\n')
Output:
Difference between map, applymap and apply in Pandas
map
| applymap
| apply
|
---|
Defined only in Series | Defined only in Dataframe | Defined in both Series and DataFrame |
Accepts dictionary, Series, or callable | Accept callables only | Accept callables only |
Series.map() Operate on one element at time | DataFrame.applymap() Operate on one element at a time | operates on entire rows or columns at a time for Dataframe, and one at a time for Series.apply |
Missing values will be recorded as NaN in the output. | Performs better operation than apply(). | Suited to more complex operations and aggregation. |
Similar Reads
What is the difference between join and merge in Pandas? In Pandas, join() combines DataFrames based on their indices and defaults to a left join, while merge() joins on specified columns and defaults to an inner join. Choosing the right method depends on how your data is aligned. To illustrate the difference between join() and merge() visually, Let's und
4 min read
Difference Between keySet() vs value() Method in Java Map Map Interface is present in Java.util package, which provides mainly three methods KeySet(),entrySet() and values(). These methods are used to retrieve the keys of the map, key-value pairs of the map, and values of the map respectively. Since these methods are part of Map Interface, so we can use ca
4 min read
Difference between Pandas VS NumPy Python is one of the most popular languages for Machine Learning, Data Analysis, and Deep learning tasks. It is powerful because of its libraries that provide the user full command over the data. Today, we will look into the most popular libraries i.e. NumPy and Pandas in Python, and then we will co
3 min read
Difference Between value() vs entrySet() Method in Java Map Map Interface is present in Java.util package, which provides mainly three methods KeySet(),entrySet() and values(). These methods are used to retrieve the keys of the map, key-value pairs of the map, and values of the map respectively. Since these methods are part of Map Interface, so we can use ca
5 min read
Difference Between map() And flatMap() In Java Stream In Java, the Stream interface has a map() and flatmap() methods and both have intermediate stream operation and return another stream as method output. Both of the functions map() and flatMap are used for transformation and mapping operations. map() function produces one output for one input value,
3 min read
Difference between Pandas and PostgreSQL Pandas: Python supports an in-built library Pandas, to perform data analysis and manipulation is a fast and efficient way. Pandas library handles data available in uni-dimensional arrays, called series, and multi-dimensional arrays called data frames. It provides a large variety of functions and uti
4 min read