Numeric_only in pandas. If numeric_only =False

Hello

I have a question about pd.DataFrame.max() method. Inside it, we use numeric_only parameter to specify as boolean. If we do not write ‘true’ , I do not get what it prints. I checked writing numeric_only = false to the f500 DataFrame. It printed a table with some strings in it as well, so I decided to ask to understand what this actually prints. What string values it takes when numeric_only = False

Best Regards

1 Like

Others will be able to help you out better if you -

  • Included the link to the Mission/ Mission Step you are referring to here.
  • The actual code you used
  • The output you got from that code

Helps provide others with better context to be able to help out.

Hello @shhuseynli2018


numeric_only parameter accepts bool, If you assign it to True, it will return only numeric columns, if you assign it to False it will use everything.
Check out the Documentation I’ve attached above.
This is what the documentation is saying about the numeric_only parameter:

numeric_only bool, default None
Include only float, int, boolean columns. If None, will attempt to use everything, then use only numeric data. Not implemented for Series.

@shhuseynli2018
print(f500.max(numeric_only=True)) gives you maximum value of all numeric value contained columns.
So when you’re specify you want to apply the method max only on numeric values of dataframe by numeric_only=True which is by default numeric_only=None, so your
f500.max(numeric_only=False) and f500.max() are actually the same.

Infact you specifies that you want to apply the method max only on numeric values of dataframe by numeric_only=True
That’s why you are getting output for only numeric values in this case.
And you specifies that you want to apply the method max both numeric values and obejct(or non-numeric value such as string) dataframe by numeric_only=False
That’s why you are getting output for both numeric values and obejct(or non-numeric value such as string) in this case.

Thanks for the explanation! My main question is when numeric_only = None, what values it prints from strings? In other words, what does max method do to strings?

Thanks for the respond! My main question is what does ‘max’ method do to strings when numeric_only = None ?

@ *

In case of single string:


max() compares the ascii value in case of string.

In case of multiple strings, it will retrieve the string as maximum value of which the first character has the maximum ascii value among all string’s first character by default.

Thank you very much for the explanation! I got it!

1 Like