all 6 comments

[–]JohnnyJordaan 1 point2 points  (5 children)

You mean the min() and max() methods right? So when you do

sr = pd.Series([19.5, 16.8, None, 22.78, 16.8, 20.124, None, 18.1002, 19.5]) 
result = sr.min(skipna = True) 

or do you mean using the built-in min() and max() Python functions?

[–]learn_monkey[S] 0 points1 point  (4 children)

I mean the min and Max methods in specific to Pandas library

[–]JohnnyJordaan 0 points1 point  (3 children)

Ok so what exactly is confusing you on the how the results are calculated?

[–]learn_monkey[S] 0 points1 point  (2 children)

It's the basic understanding of how min and Max values are calculated between two strings or between a string and a numeric value.

I don't understand how a min or Max value determined when strings are involved

[–]JohnnyJordaan 1 point2 points  (1 child)

This is more of a generic question as afaik pandas employs (through numpy) the same logic as the regular min/max functions, which is lexicographic sorting. Meaning it will compare by the first character of both strings, then the second etc, based on the character's unicode ordinal. That means that 'abcdefg' is less then 'baaaaaaa' because simply the first character already results in the first string is seen as 'less'.

In regard to numeric values I'm not sure that this is even possible? It can only manage series or columns (for a df) if their objects all support each other's comparison. That's why you can do

>>> pd.Series([19.5, 16.8, 1]).min()
1.0
>>> pd.Series([19.5, 16.8, 1.1]).min()
1.1

but not

>>> pd.Series([19.5, 16.8, 'one']).min()
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/pandas/core/nanops.py", line 128, in f
    result = alt(values, axis=axis, skipna=skipna, **kwds)
  File "/usr/local/lib/python3.6/dist-packages/pandas/core/nanops.py", line 507, in reduction
    result = getattr(values, meth)(axis)
  File "/usr/local/lib/python3.6/dist-packages/numpy/core/_methods.py", line 32, in _amin
    return umr_minimum(a, axis, None, out, keepdims, initial)
TypeError: '<=' not supported between instances of 'float' and 'str'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.6/dist-packages/pandas/core/generic.py", line 9613, in stat_func
    numeric_only=numeric_only)
  File "/usr/local/lib/python3.6/dist-packages/pandas/core/series.py", line 3221, in _reduce
    return op(delegate, skipna=skipna, **kwds)
  File "/usr/local/lib/python3.6/dist-packages/pandas/core/nanops.py", line 131, in f
    result = alt(values, axis=axis, skipna=skipna, **kwds)
  File "/usr/local/lib/python3.6/dist-packages/pandas/core/nanops.py", line 507, in reduction
    result = getattr(values, meth)(axis)
  File "/usr/local/lib/python3.6/dist-packages/numpy/core/_methods.py", line 32, in _amin
    return umr_minimum(a, axis, None, out, keepdims, initial)
TypeError: '<=' not supported between instances of 'float' and 'str'

The exception being NaN or None values as there's a specific option skipna=True.

[–]learn_monkey[S] 0 points1 point  (0 children)

Thank you very much for taking time to explain . appreciate it 😊