Reputation: 21
I have a big dataframe. I want to classify my data like this:
if element > threshold:
element = 1
elif element < -threshold:
element = -1
else:
element = 0
Trying to do it like this in pandas, but it obviously leaves out the range [-threshold,threshold]. Is there a way to use "else" on an entire column?
for col in data:
data[col][data[col] > threshold] = 1
data[col][data[col] < -threshold] = -1
Upvotes: 1
Views: 251