当min(list)为科学计数法时如何修复list.index(min(list))

时间:2019-04-30 22:01:05

标签: python python-3.x numpy data-science

不言自明,我的清单的最小值为3.4972054734350166e-06。我想找到列表在哪里使用

list.index(min(list))

但给出了以下错误:

KeyError                                  Traceback (most recent call last)

<ipython-input-75-218f090090e9> in <module>()
     15 print(sum(list) / len(list))
     16 print("The highest r2 value is:",max(list),"from ",country_data[list.index(max(list))].name[0])
---> 17 print(country_data[list.index(min(list))].name[0])

1 frames

/usr/local/lib/python3.6/dist-packages/pandas/core/indexes/base.py in get_value(self, series, key)
   4373         try:
   4374             return self._engine.get_value(s, k,
-> 4375                                           tz=getattr(series.dtype, 'tz', None))
   4376         except KeyError as e1:
   4377             if len(self) > 0 and (self.holds_integer() or self.is_boolean()):

pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_value()

pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_value()

pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()

pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.Int64HashTable.get_item()

pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.Int64HashTable.get_item()

KeyError: 0

代码与index(max(list))一起使用。

2 个答案:

答案 0 :(得分:2)

尝试这种方式list_name.index(min(list_name));)

答案 1 :(得分:0)

由于您根据标签使用了numpy,因此只需使用argminaxis=None

  

numpy.argmin

     

返回沿轴的最小值的索引。

np.argmin(arr)