@@ -976,17 +976,59 @@ def str_get_dummies(arr, sep='|'):
976
976
977
977
def str_join (arr , sep ):
978
978
"""
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`.
981
984
982
985
Parameters
983
986
----------
984
- sep : string
985
- Delimiter
987
+ sep : str
988
+ Delimiter to use between list entries.
986
989
987
990
Returns
988
991
-------
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
990
1032
"""
991
1033
return _na_map (sep .join , arr )
992
1034
0 commit comments