@@ -51,46 +51,56 @@ def str_cat(arr, others=None, sep=None, na_rep=None):
51
51
"""
52
52
Concatenate strings in the Series/Index with given separator.
53
53
54
+ If `others` is specified, this function concatenates the Series/Index
55
+ and elements of `others` element-wise.
56
+ If `others` is not being passed then all values in the Series are
57
+ concatenated in a single string with a given `sep`.
58
+
54
59
Parameters
55
60
----------
56
- others : list-like, or list of list-likes
57
- If None, returns str concatenating strings of the Series
61
+ others : list-like, or list of list-likes, optional
62
+ List-likes (or a list of them) of the same length as calling object.
63
+ If None, returns str concatenating strings of the Series.
58
64
sep : string or None, default None
65
+ If None, concatenates without any separator.
59
66
na_rep : string or None, default None
60
67
If None, NA in the series are ignored.
61
68
62
69
Returns
63
70
-------
64
71
concat : Series/Index of objects or str
65
72
73
+ See Also
74
+ --------
75
+ split : Split each string in the Series/Index
76
+
66
77
Examples
67
78
--------
68
- When ``na_rep`` is `None` (default behavior), NaN value(s)
69
- in the Series are ignored.
79
+ When not passing `other`, all values are concatenated into a single
80
+ string:
70
81
71
- >>> Series(['a','b',np.nan,'c']).str.cat(sep=' ')
82
+ >>> s = pd.Series(['a', 'b', np.nan, 'c'])
83
+ >>> s.str.cat(sep=' ')
72
84
'a b c'
73
85
74
- >>> Series(['a','b',np.nan,'c']).str.cat(sep=' ', na_rep='?')
86
+ By default, NA values in the Series are ignored. Using `na_rep`, they
87
+ can be given a representation:
88
+
89
+ >>> pd.Series(['a', 'b', np.nan, 'c']).str.cat(sep=' ', na_rep='?')
75
90
'a b ? c'
76
91
77
- If `` others` ` is specified, corresponding values are
92
+ If `others` is specified, corresponding values are
78
93
concatenated with the separator. Result will be a Series of strings.
79
94
80
- >>> Series(['a', 'b', 'c']).str.cat(['A', 'B', 'C'], sep=',')
95
+ >>> pd. Series(['a', 'b', 'c']).str.cat(['A', 'B', 'C'], sep=',')
81
96
0 a,A
82
97
1 b,B
83
98
2 c,C
84
99
dtype: object
85
100
86
- Otherwise, strings in the Series are concatenated. Result will be a string.
87
-
88
- >>> Series(['a', 'b', 'c']).str.cat(sep=',')
89
- 'a,b,c'
90
-
91
101
Also, you can pass a list of list-likes.
92
102
93
- >>> Series(['a', 'b']).str.cat([['x', 'y'], ['1', '2']], sep=',')
103
+ >>> pd. Series(['a', 'b']).str.cat([['x', 'y'], ['1', '2']], sep=',')
94
104
0 a,x,1
95
105
1 b,y,2
96
106
dtype: object
0 commit comments