Examples

In [1]:
import numpy as np
import pandas as pd
In [2]:
data = {'c_0': [11, -9, 0, -3, 5], 'c_1': [-4, -7, 8, 12, -5]}
df = pd.DataFrame(data)
df
Out[2]:
c_0 c_1
0 11 -4
1 -9 -7
2 0 8
3 -3 12
4 5 -5

Clips per column using lower and upper thresholds:

In [3]:
df.clip(-8, 12)
Out[3]:
c_0 c_1
0 11 -4
1 -8 -7
2 0 8
3 -3 12
4 5 -5

Clips using specific lower and upper thresholds per column element:

In [4]:
t = pd.Series([3, -4, -1, 6, 5])
t
Out[4]:
0    3
1   -4
2   -1
3    6
4    5
dtype: int64
In [5]:
df.clip(t, t + 4, axis=0)
Out[5]:
c_0 c_1
0 7 3
1 -4 -4
2 0 3
3 6 10
4 5 5