Python 基于数组选择数据帧的一部分

Python 基于数组选择数据帧的一部分,python,dataframe,Python,Dataframe,我有一个数据帧,我希望选择一个数据帧的一部分,它等于我拥有的数组中的一个元素。 此数组将在循环中更改。例如,这里的数组表示“4”,这意味着我要选择预测值为4的数据帧的所有情况。但是我得到了一个错误,我怎么能说它应该等于数组中的元素呢 提前谢谢你 print min_idx[0] df.prediction==min_idx[0] [4] --------------------------------------------------------------------------

我有一个数据帧,我希望选择一个数据帧的一部分,它等于我拥有的数组中的一个元素。 此数组将在循环中更改。例如,这里的数组表示“4”,这意味着我要选择预测值为4的数据帧的所有情况。但是我得到了一个错误,我怎么能说它应该等于数组中的元素呢

提前谢谢你

 print min_idx[0]
 df.prediction==min_idx[0]

 [4]

 ---------------------------------------------------------------------------
 ValueError                                Traceback (most recent call last)
 <ipython-input-70-1a77e690dc3d> in <module>()
  1 print min_idx[0]
 ----> 2 df.prediction==min_idx[0]

 C:\Users\A\Anaconda2\lib\site-packages\pandas\core\ops.pyc in wrapper 
 (self,     other, axis)
     820             if (not lib.isscalar(lib.item_from_zerodim(other)) and
     821                     len(self) != len(other)):
 --> 822                 raise ValueError('Lengths must match to compare')
     823 
     824             if isinstance(other, ABCPeriodIndex):

 ValueError: Lengths must match to compare
print min_idx[0]
df.prediction==min_idx[0]
[4]
---------------------------------------------------------------------------
ValueError回溯(最近一次调用上次)
在()
1打印最小idx[0]
---->2 df.prediction==min_idx[0]
包装中的C:\Users\A\Anaconda2\lib\site packages\pandas\core\ops.pyc
(自身、其他、轴)
820如果(不是库isscalar(库项来自zerodim(其他))和
821 len(self)!=len(other)):
-->822 raise VALUERROR('长度必须匹配才能比较')
823
824如果存在(其他,ABCPeriodIndex):
ValueError:长度必须匹配才能进行比较

min\u idx[0]
似乎正在返回一个列表。如果您尝试
min\u idx[0][0]
,会发生什么?是!!它起作用了!谢谢