我需要找到 coulmntwo
值介于1.5
和之间的所有行3.5
。我期望的结果是索引为 1 和 2 的行。我尝试了以下代码,但出现错误。
>>> d = {'one' : [1., 2., 3., 4.],
... 'two' : [4., 3., 2., 1.],
... 'three':['a','b','c','d']}
>>> d
{'three': ['a', 'b', 'c', 'd'], 'two': [4.0, 3.0, 2.0, 1.0], 'one': [1.0, 2.0, 3.0, 4.0]}
>>> DataFrame(d)
one three two
0 1 a 4
1 2 b 3
2 3 c 2
3 4 d 1
>>> df = DataFrame(d)
>>> df[1.5 <= df['two'] <= 3.5]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
>>>