Pandas DataFrame applymap() Method
Example
Apply a function to the DataFrame that will upper case the values:
import pandas as pd
def make_big(x):
return x.upper()
data = {
"name": ["Sally","Mary","John"],
"city":
["London", "Tokyo", "Madrid"]
}
df = pd.DataFrame(data)
newdf = df.applymap(make_big)
print(newdf)
Try it Yourself »
Definition and Usage
The applymap()
method allows you to apply one or
more functions to the DataFrame object.
Syntax
dataframe.applymap(func, args, kwargs)
Parameters
The na_action
parameter is a
keyword argument.
Parameter | Value | Description |
---|---|---|
func | Required. A function to apply to the DataFrame. | |
na_action | ignore |
Optional, Whether to ignore NULL values or not. Default is to not ignore them |
Return Value
A DataFrame object, with the changes.
This function does NOT make changes to the original DataFrame object.