What you are looking for is pandas.DataFrame.applymap
, which applies a function element-wise:
df.applymap(lambda x: -1 if x < low else (1 if x > high else 0))
The method pandas.DataFrame.apply
applies a function along a given axis (default is column-wise).
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…