Pandas – How applymap() works in Pandas

Spread the love

pandas.DataFrame.applymap –

applymap in pandas is a dataframe method. It Applies a function to each and every elements in the dataframe.

Let’s read a dataset to illustrate it.

import pandas as pd
import numpy as np
url = ""
df = pd.read_csv(url)

Let’s say that I want to round up all the values in this dataframe. To do that we can use the applymap function in pandas.

# round up all the values
df_new = df.applymap(np.ceil)

Let’s say for some reason you want to add 10 to all the values in the dataframe. You can easily do this using lambda function with applymap

df.applymap(lambda x : x + 10)

Leave a Reply