I have a dataframe with several columns and indexes and I would like to replace each value by 1 if the value is positive, -1 else.
Here is how I tried to do it but it fails and I have th efollowing error:
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
There are many other posts with the same error but none of the one I read helped.
Here is my code:
numeric_cols = [col for col in df1 if df1[col].dtype.kind != 'O']
if df1[numeric_cols] > 0:
df1[numeric_cols] = 1
else:
df1[numeric_cols] = -1