Skip to content

Commit 89444ad

Browse files
fdroesslerTomAugspurger
authored andcommitted
DOC: update the Series.str.join docstring (#20463)
1 parent 687cbe2 commit 89444ad

File tree

1 file changed

+47
-5
lines changed

1 file changed

+47
-5
lines changed

pandas/core/strings.py

+47-5
Original file line numberDiff line numberDiff line change
@@ -976,17 +976,59 @@ def str_get_dummies(arr, sep='|'):
976976

977977
def str_join(arr, sep):
978978
"""
979-
Join lists contained as elements in the Series/Index with
980-
passed delimiter. Equivalent to :meth:`str.join`.
979+
Join lists contained as elements in the Series/Index with passed delimiter.
980+
981+
If the elements of a Series are lists themselves, join the content of these
982+
lists using the delimiter passed to the function.
983+
This function is an equivalent to :meth:`str.join`.
981984
982985
Parameters
983986
----------
984-
sep : string
985-
Delimiter
987+
sep : str
988+
Delimiter to use between list entries.
986989
987990
Returns
988991
-------
989-
joined : Series/Index of objects
992+
Series/Index: object
993+
994+
Notes
995+
-----
996+
If any of the lists does not contain string objects the result of the join
997+
will be `NaN`.
998+
999+
See Also
1000+
--------
1001+
str.join : Standard library version of this method.
1002+
Series.str.split : Split strings around given separator/delimiter.
1003+
1004+
Examples
1005+
--------
1006+
1007+
Example with a list that contains non-string elements.
1008+
1009+
>>> s = pd.Series([['lion', 'elephant', 'zebra'],
1010+
... [1.1, 2.2, 3.3],
1011+
... ['cat', np.nan, 'dog'],
1012+
... ['cow', 4.5, 'goat']
1013+
... ['duck', ['swan', 'fish'], 'guppy']])
1014+
>>> s
1015+
0 [lion, elephant, zebra]
1016+
1 [1.1, 2.2, 3.3]
1017+
2 [cat, nan, dog]
1018+
3 [cow, 4.5, goat]
1019+
4 [duck, [swan, fish], guppy]
1020+
dtype: object
1021+
1022+
Join all lists using an '-', the lists containing object(s) of types other
1023+
than str will become a NaN.
1024+
1025+
>>> s.str.join('-')
1026+
0 lion-elephant-zebra
1027+
1 NaN
1028+
2 NaN
1029+
3 NaN
1030+
4 NaN
1031+
dtype: object
9901032
"""
9911033
return _na_map(sep.join, arr)
9921034

0 commit comments

Comments
 (0)