2017-06-21 93 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)