[英]How to fix list.index(min(list)) when min(list) is in scientific notation
Pretty self explanatory, my list has a smallest value of 3.4972054734350166e-06. 不言而喻,我的清单的最小值为3.4972054734350166e-06。 I want to find where in the list this is using
我想在列表中找到该位置
list.index(min(list))
but it gives an error of: 但它给出了以下错误:
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
The code works with index(max(list)). 该代码与index(max(list))一起使用。
尝试这种方式list_name.index(min(list_name));)
Since you are using numpy
according to your tag, simply use argmin
letting axis=None
由于您根据标签使用
numpy
,因此只需使用argmin
axis=None
numpy.argmin
numpy.argmin
Returns the indices of the minimum values along an axis.
返回沿轴的最小值的索引。
np.argmin(arr)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.