If you won't need to do many other numerical operations and you have a reason for preferring the data to reside in str
format, you can always use the native Python min
and max
operating on a plain list
of your data:
In [98]: col = np.asarray(['6.7', '0.9', '1.3', '4', '1.8'])
In [99]: col
Out[99]:
array(['6.7', '0.9', '1.3', '4', '1.8'],
dtype='|S3')
In [100]: col.min()
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-100-1ce0c6ec1def> in <module>()
----> 1 col.min()
TypeError: cannot perform reduce with flexible type
In [101]: col.tolist()
Out[101]: ['6.7', '0.9', '1.3', '4', '1.8']
In [102]: min(col.tolist())
Out[102]: '0.9'
In [103]: max(col.tolist())
Out[103]: '6.7'
In general, this isn't a good way to handle numerical data and could be susceptible to many faulty assumptions about what resides in your array. But it's just another option to consider if you need to or if you have a special reason for working with strings (such as, you're only ever calculating the min and max and all you do with them is display them).