Skip to content

Commit d67b513

Browse files
phoflKevin D Smith
authored and
Kevin D Smith
committed
[DOC]: Add explanation about DataFrame methods use all Categories (pandas-dev#36747)
\
1 parent 713fcda commit d67b513

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

doc/source/user_guide/categorical.rst

+13
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,19 @@ even if some categories are not present in the data:
618618
s = pd.Series(pd.Categorical(["a", "b", "c", "c"], categories=["c", "a", "b", "d"]))
619619
s.value_counts()
620620
621+
``DataFrame`` methods like :meth:`DataFrame.sum` also show "unused" categories.
622+
623+
.. ipython:: python
624+
625+
columns = pd.Categorical(
626+
["One", "One", "Two"], categories=["One", "Two", "Three"], ordered=True
627+
)
628+
df = pd.DataFrame(
629+
data=[[1, 2, 3], [4, 5, 6]],
630+
columns=pd.MultiIndex.from_arrays([["A", "B", "B"], columns]),
631+
)
632+
df.sum(axis=1, level=1)
633+
621634
Groupby will also show "unused" categories:
622635

623636
.. ipython:: python

0 commit comments

Comments
 (0)