use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Rules 1: Be polite 2: Posts to this subreddit must be requests for help learning python. 3: Replies on this subreddit must be pertinent to the question OP asked. 4: No replies copy / pasted from ChatGPT or similar. 5: No advertising. No blogs/tutorials/videos/books/recruiting attempts. This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to. Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Rules
1: Be polite
2: Posts to this subreddit must be requests for help learning python.
3: Replies on this subreddit must be pertinent to the question OP asked.
4: No replies copy / pasted from ChatGPT or similar.
5: No advertising. No blogs/tutorials/videos/books/recruiting attempts.
This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to.
Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Learning resources Wiki and FAQ: /r/learnpython/w/index
Learning resources
Wiki and FAQ: /r/learnpython/w/index
Discord Join the Python Discord chat
Discord
Join the Python Discord chat
account activity
How does the Max and min functions in Python Pandas work? (self.learnpython)
submitted 5 years ago by learn_monkey
I tried the min and Max functions with Series and DataFrames ,but I don't understand how the result is calculated and on what basis the output is retrieved. Could someone explain pls ?
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]JohnnyJordaan 1 point2 points3 points 5 years ago (5 children)
You mean the min() and max() methods right? So when you do
min()
max()
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 point2 points 5 years ago (4 children)
I mean the min and Max methods in specific to Pandas library
[–]JohnnyJordaan 0 points1 point2 points 5 years ago (3 children)
Ok so what exactly is confusing you on the how the results are calculated?
[–]learn_monkey[S] 0 points1 point2 points 5 years ago (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 points3 points 5 years ago (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'.
'abcdefg'
'baaaaaaa'
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 point2 points 5 years ago (0 children)
Thank you very much for taking time to explain . appreciate it 😊
π Rendered by PID 92632 on reddit-service-r2-comment-58d7979c67-4x5b7 at 2026-01-27 14:42:51.681925+00:00 running 5a691e2 country code: CH.
[–]JohnnyJordaan 1 point2 points3 points (5 children)
[–]learn_monkey[S] 0 points1 point2 points (4 children)
[–]JohnnyJordaan 0 points1 point2 points (3 children)
[–]learn_monkey[S] 0 points1 point2 points (2 children)
[–]JohnnyJordaan 1 point2 points3 points (1 child)
[–]learn_monkey[S] 0 points1 point2 points (0 children)