2017-06-21 101 views
1

我有一个很大的数据框。我想我的数据进行分类是这样的:熊猫标签数据

if element > threshold: 
    element = 1 
elif element < -threshold: 
    element = -1 
else: 
    element = 0 

试图做这样的大熊猫,但它显然遗漏了范围[-threshold,门槛。有没有办法在整个列上使用“其他”?

for col in data: 
    data[col][data[col] > threshold] = 1 
    data[col][data[col] < -threshold] = -1 

回答

1

使用np.sign

np.sign(data - threshold)