-
Series.str.cat(others=None, sep=None, na_rep=None)
[source] -
Concatenate strings in the Series/Index with given separator.
Parameters: others : list-like, or list of list-likes
If None, returns str concatenating strings of the Series
sep : string or None, default None
na_rep : string or None, default None
If None, NA in the series are ignored.
Returns: concat : Series/Index of objects or str
Examples
When
na_rep
isNone
(default behavior), NaN value(s) in the Series are ignored.12>>> Series([
'a'
,
'b'
,np.nan,
'c'
]).
str
.cat(sep
=
' '
)
'a b c'
12>>> Series([
'a'
,
'b'
,np.nan,
'c'
]).
str
.cat(sep
=
' '
, na_rep
=
'?'
)
'a b ? c'
If
others
is specified, corresponding values are concatenated with the separator. Result will be a Series of strings.12345>>> Series([
'a'
,
'b'
,
'c'
]).
str
.cat([
'A'
,
'B'
,
'C'
], sep
=
','
)
0
a,A
1
b,B
2
c,C
dtype:
object
Otherwise, strings in the Series are concatenated. Result will be a string.
12>>> Series([
'a'
,
'b'
,
'c'
]).
str
.cat(sep
=
','
)
'a,b,c'
Also, you can pass a list of list-likes.
1234>>> Series([
'a'
,
'b'
]).
str
.cat([[
'x'
,
'y'
], [
'1'
,
'2'
]], sep
=
','
)
0
a,x,
1
1
b,y,
2
dtype:
object
Series.str.cat()

2025-01-10 15:47:30
Please login to continue.