Examples

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

Clips per column using lower and upper thresholds:

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

Clips using specific lower and upper thresholds per column element:

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