You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Since rank correlation coefficients make sense also for ordinal data, documentation for option numeric_true is a little confusing.
Currently, it's saying the following:
numeric_only : bool, default False
Include only `float`, `int` or `boolean` data.
When ordinal data (categorical dtype with defined order) presented in dataframe, it seems natural to expect that rank correlation still be computed when using numeric_only = False. For example, something like this should work:
Yet it throws ValueError, since it cannot convert string low to float. Moreover, using numerical categories with the specific order results in incorrect behavior. For example,
returns that Spearman's correlation between a and b is equal to -1, while real value is equal to 1.
Suggested fix for documentation
I believe, that following additional sentence makes things a bit less confusing.
numeric_only : bool, default False
Include only `float`, `int` or `boolean` data. If value is False, method will try cast non-numerical
columns to float (note that ordinal data, if possible, will be converted ignoring specified order)
The text was updated successfully, but these errors were encountered:
Thanks for the report. It appears to me that these (spearman on non-numeric data and categorical order not being respected) are bugs. I think the latter is covered in #33245, so we can have this issue be above the former.
rhshadrach
changed the title
DOC: numeric_only option for DataFrame.corr is unclear
BUG: spearman correlation doesn't work on non-numeric data
Nov 14, 2024
Pandas version checks
main
hereLocation of the documentation
https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.corr.html#pandas.DataFrame.corr
Documentation problem
Since rank correlation coefficients make sense also for ordinal data, documentation for option
numeric_true
is a little confusing.Currently, it's saying the following:
When ordinal data (categorical dtype with defined order) presented in dataframe, it seems natural to expect that rank correlation still be computed when using
numeric_only = False
. For example, something like this should work:Yet it throws
ValueError
, since it cannot convert stringlow
to float. Moreover, using numerical categories with the specific order results in incorrect behavior. For example,returns that Spearman's correlation between
a
andb
is equal to -1, while real value is equal to 1.Suggested fix for documentation
I believe, that following additional sentence makes things a bit less confusing.
The text was updated successfully, but these errors were encountered: