I'm new to python... So, i wrote this function that should normalize the price values contained in the "price" column of my dataframe:
def normalize_price(df):
for elements in df['price']:
if (df["price"]>= 1000) and (df['price']<= 1499):
df['price'] = 1000
return
elif 1500 <= df['price'] <= 2499:
df['price'] = 1500
return
elif 2500 <= df['price'] <= 2999:
df['price'] = 2500
return
elif 3000 <= df['price'] <= 3999:
df['price'] = 3000
return
So, when I call it I get the error
---------------------------------------------------------------------------
<ipython-input-86-1e239d3cbba4> in normalize_price(df)
20 def normalize_price(df):
21 for elements in df['price']:
---> 22 if (df["price"]>= 1000) and (df['price']<= 1499):
23 df['price'] = 1000
24 return
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
And since I'm going crazy, I'd like to know why :) Thanks!