Examples

In [1]:
import numpy as np
import pandas as pd
In [2]:
df = pd.DataFrame([[2, 3.12], [4.356, 5.567]])
df
Out[2]:
0 1
0 2.000 3.120
1 4.356 5.567

Pandas: Dataframe - applymap.

In [3]:
df.applymap(lambda x: len(str(x)))
Out[3]:
0 1
0 3 4
1 5 5

You could square each number elementwise:

In [4]:
df.applymap(lambda x: x**2)
Out[4]:
0 1
0 4.000000 9.734400
1 18.974736 30.991489

But it’s better to avoid applymap in that case.

In [5]:
df ** 2
Out[5]:
0 1
0 4.000000 9.734400
1 18.974736 30.991489