import numpy as np
import pandas as pd
df = pd.DataFrame([[0.01,0.01],[0.2,0.2]])
# df
# 0 1
# 0 0.01 0.01
# 1 0.20 0.20
def binarization(x, threshold, pos=1, neg=0):
if x >= threshold:
return pos
else:
return neg
df = df.apply(np.vectorize(binarization),args=(0.1,))
# df
# 0 1
# 0 0 0
# 1 1 1