How can we get different stats behind a plotly boxplot?

Viewed 71

I'd like to get the exact stats behind a plotly boxplot.

This seems to get me pretty close, but I'm missing Q1 and Q3.

stats = df.groupby(['Market'])['Revenue'].describe()
stats

The Q1 and Q3 seem to be different than what I see from this.

import plotly.express as px
fig = px.box(df, x="Market", y="Revenue", color="Market")
fig.update_traces(quartilemethod="exclusive")
fig.update_layout(showlegend=False)
fig.show()

It has something to do with the 'exclusive' or 'inclusive' argument, but I don't know what the difference is. Also, the default for df.groupby(['Market'])['Revenue'].describe() seems to match the 'inclusive' argument.

Q1: what's the difference between 'exclusive' and 'inclusive'?

Q2: does df.groupby(['Market'])['Revenue'].describe() have an 'exclusive' argument?

1 Answers

Q1

I haven't found a description in the plotly docs, but it's fair to assume that the explanation would not differ much from Percentile:

In statistics, a percentile (or a centile) is a score below which a given percentage of scores in its frequency distribution falls (exclusive definition) or a score at or below which a given percentage falls (inclusive definition). For example, the 50th percentile (the median) is the score below which (exclusive) or at or below which (inclusive) 50% of the scores in the distribution may be found.

You can take a closer look at a visual representation of the differences under Difference Between Quartile Algorithms in the plotly docs:

enter image description here

Q2

No, df.describe() does not seem to have an exclusive argument:

Help on method describe in module pandas.core.generic:

describe(percentiles=None, include=None, exclude=None, datetime_is_numeric=False) -> ~FrameOrSeries method of pandas.core.frame.DataFrame instance

As you can see, it does however have include and exclude. But they do very different things from what you're looking for:

include : 'all', list-like of dtypes or None (default), optional A white list of data types to include in the result. Ignored for Series. Here are the options:

    - 'all' : All columns of the input will be included in the output.
    - A list-like of dtypes : Limits the results to the
      provided data types.
      To limit the result to numeric types submit
      ``numpy.number``. To limit it instead to object columns submit
      the ``numpy.object`` data type. Strings
      can also be used in the style of
      ``select_dtypes`` (e.g. ``df.describe(include=['O'])``). To
      select pandas categorical columns, use ``'category'``
    - None (default) : The result will include all numeric columns.
exclude : list-like of dtypes or None (default), optional,
    A black list of data types to omit from the result. Ignored
    for ``Series``. Here are the options:

    - A list-like of dtypes : Excludes the provided data types
      from the result. To exclude numeric types submit
      ``numpy.number``. To exclude object columns submit the data
      type ``numpy.object``. Strings can also be used in the style of
      ``select_dtypes`` (e.g. ``df.describe(include=['O'])``). To
      exclude pandas categorical columns, use ``'category'``
    - None (default) : The result will exclude nothing.
Related