Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 24 additions & 12 deletions pandas/core/strings/accessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -526,11 +526,12 @@ def cat(
to match the length of the calling Series/Index). To disable
alignment, use `.values` on any Series/Index/DataFrame in `others`.

Returns
-------
str, Series or Index
If `others` is None, `str` is returned, otherwise a `Series/Index`
(same type as caller) of objects is returned.
Returns
-------
str, Series or Index
- If the caller is a Series and `others` is None, a single concatenated `str` is returned.
- If the caller is an Index and `others` is None, an Index of length 1 containing the concatenated string is returned.
- If `others` is specified, the result is a Series or Index (same type as caller) of concatenated strings.

See Also
--------
Expand Down Expand Up @@ -608,14 +609,25 @@ def cat(
dtype: object
>>>
>>> s.str.cat(t, join="right", na_rep="-")
3 dd
0 aa
4 -e
2 -c
dtype: object
3 dd
0 aa
4 -e
2 -c
dtype: object

When calling `.str.cat()` on an Index and not passing `others`, the return value is an Index:

>>> idx = pd.Index(["x", "y", np.nan])
>>> idx.str.cat(sep="-")
Index(['x-y'], dtype='object')

Note
----
Calling `.str.cat()` on a Series returns a string if `others` is None,
but when called on an Index, it returns a new Index containing the concatenated string.

For more examples, see :ref:`here <text.concatenate>`.

For more examples, see :ref:`here <text.concatenate>`.
"""
# TODO: dispatch
from pandas import (
Index,
Expand Down
Loading