Skip to content

Commit 5ef5dfb

Browse files
authored
DOC: fix doc for crosstab with Categorical data input (#33783)
* fix doc for crosstab with Categorical data input * fix doc for crosstab with Categorical data input * put dropna=False in a separate ipython block
1 parent f683473 commit 5ef5dfb

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

doc/source/user_guide/reshaping.rst

+11-3
Original file line numberDiff line numberDiff line change
@@ -471,16 +471,24 @@ If ``crosstab`` receives only two Series, it will provide a frequency table.
471471
472472
pd.crosstab(df['A'], df['B'])
473473
474-
Any input passed containing ``Categorical`` data will have **all** of its
475-
categories included in the cross-tabulation, even if the actual data does
476-
not contain any instances of a particular category.
474+
``crosstab`` can also be implemented
475+
to ``Categorical`` data.
477476

478477
.. ipython:: python
479478
480479
foo = pd.Categorical(['a', 'b'], categories=['a', 'b', 'c'])
481480
bar = pd.Categorical(['d', 'e'], categories=['d', 'e', 'f'])
482481
pd.crosstab(foo, bar)
483482
483+
If you want to include **all** of data categories even if the actual data does
484+
not contain any instances of a particular category, you should set ``dropna=False``.
485+
486+
For example:
487+
488+
.. ipython:: python
489+
490+
pd.crosstab(foo, bar, dropna=False)
491+
484492
Normalization
485493
~~~~~~~~~~~~~
486494

0 commit comments

Comments
 (0)