I need to apply a very simple if/then function to every element in a Pandas Dataframe.
If the value of any element is over 0.5, I need to return a 1. Otherwise, I need to return a 0.
This seemed really simple with a lambda function, but every time I try I get an error: 'ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all()'
So far I have:
df_new = df.apply(lambda x: 1 if x > 0.5 else 1)
I'd be grateful for any help.