Skip to content

Commit e56246d

Browse files
committed
DOC: Clarify str.cat output for Index object (GH35556)
1 parent 9da2c8f commit e56246d

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

pandas/core/strings/accessor.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -608,14 +608,25 @@ def cat(
608608
dtype: object
609609
>>>
610610
>>> s.str.cat(t, join="right", na_rep="-")
611-
3 dd
612-
0 aa
613-
4 -e
614-
2 -c
615-
dtype: object
611+
3 dd
612+
0 aa
613+
4 -e
614+
2 -c
615+
dtype: object
616+
617+
When calling `.str.cat()` on an Index and not passing `others`, the return value is an Index:
618+
619+
>>> idx = pd.Index(["x", "y", np.nan])
620+
>>> idx.str.cat(sep="-")
621+
Index(['x-y'], dtype='object')
622+
623+
Note
624+
----
625+
Calling `.str.cat()` on a Series returns a string if `others` is None,
626+
but when called on an Index, it returns a new Index containing the concatenated string.
627+
628+
For more examples, see :ref:`here <text.concatenate>`.
616629
617-
For more examples, see :ref:`here <text.concatenate>`.
618-
"""
619630
# TODO: dispatch
620631
from pandas import (
621632
Index,

0 commit comments

Comments
 (0)