Pretty self explanatory, my list has a smallest value of 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)).
尝试这种方式list_name.index(min(list_name));)
Since you are using numpy
according to your tag, simply use argmin
letting axis=None
numpy.argmin
Returns the indices of the minimum values along an axis.
np.argmin(arr)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.