Let's say I have data frame of integer values 0 t0 100. and I want to classify these values into 3 parts, low, mid and high with low being less than 33, high being greater than 66 and mid is in between 33 and 66. So I use
df['low'] = df['int'] <= 33
df['mid'] = 33 < df['int'] < 66
df['high'] = df['int'] >= 66
and i get error
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_12080/1299746928.py in <module>
1 df['low'] = df['int'] <= 33
----> 2 df['mid'] = 33 < df['int'] < 66
3 df['high'] = df['int'] >= 66
c:\program files\python37\lib\site-packages\pandas\core\generic.py in __nonzero__(self)
1536 def __nonzero__(self):
1537 raise ValueError(
-> 1538 f"The truth value of a {type(self).__name__} is ambiguous. "
1539 "Use a.empty, a.bool(), a.item(), a.any() or a.all()."
1540 )
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
I have alredy tried if else statement and also and
and other operator.
low and high works, but the mid doesn't work.
please can I know any way around?