cat(self, others=None, sep=None, na_rep=None, join='left') -> 'str | Series | Index'
If :None:None:`others`
is specified, this function concatenates the Series/Index and elements of :None:None:`others`
element-wise. If :None:None:`others`
is not passed, then all values in the Series/Index are concatenated into a single string with a given sep
.
Series, Index, DataFrame, np.ndarray (one- or two-dimensional) and other list-likes of strings must have the same length as the calling Series/Index, with the exception of indexed objects (i.e. Series/Index/DataFrame) if join
is not None.
If others is a list-like that contains a combination of Series, Index or np.ndarray (1-dim), then all elements will be unpacked and must satisfy the above criteria individually.
If others is None, the method returns the concatenation of all strings in the calling Series/Index.
The separator between the different elements/columns. By default the empty string :None:None:`''`
is used.
Representation that is inserted for all missing values:
Determines the join-style between the calling Series/Index and any Series/Index/DataFrame in :None:None:`others`
(objects without an index need to match the length of the calling Series/Index). To disable alignment, use :None:None:`.values`
on any Series/Index/DataFrame in :None:None:`others`
.
Changed default of :None:None:`join`
from None to :None:None:`'left'`
.
If :None:None:`others`
is None, :None:None:`str`
is returned, otherwise a :None:None:`Series/Index`
(same type as caller) of objects is returned.
Concatenate strings in the Series/Index with given separator.
join
Join lists contained as elements in the Series/Index.
split
Split each string in the Series/Index.
When not passing :None:None:`others`
, all values are concatenated into a single string:
>>> s = pd.Series(['a', 'b', np.nan, 'd'])
... s.str.cat(sep=' ') 'a b d'
By default, NA values in the Series are ignored. Using na_rep
, they can be given a representation:
>>> s.str.cat(sep=' ', na_rep='?') 'a b ? d'
If :None:None:`others`
is specified, corresponding values are concatenated with the separator. Result will be a Series of strings.
>>> s.str.cat(['A', 'B', 'C', 'D'], sep=',') 0 a,A 1 b,B 2 NaN 3 d,D dtype: object
Missing values will remain missing in the result, but can again be represented using na_rep
>>> s.str.cat(['A', 'B', 'C', 'D'], sep=',', na_rep='-') 0 a,A 1 b,B 2 -,C 3 d,D dtype: object
If sep
is not specified, the values are concatenated without separation.
>>> s.str.cat(['A', 'B', 'C', 'D'], na_rep='-') 0 aA 1 bB 2 -C 3 dD dtype: object
Series with different indexes can be aligned before concatenation. The join
-keyword works as in other methods.
>>> t = pd.Series(['d', 'a', 'e', 'c'], index=[3, 0, 4, 2])This example is valid syntax, but we were not able to check execution
... s.str.cat(t, join='left', na_rep='-') 0 aa 1 b- 2 -c 3 dd dtype: object >>>
>>> s.str.cat(t, join='outer', na_rep='-') 0 aa 1 b- 2 -c 3 dd 4 -e dtype: object >>>This example is valid syntax, but we were not able to check execution
>>> s.str.cat(t, join='inner', na_rep='-') 0 aa 2 -c 3 dd dtype: object >>>This example is valid syntax, but we were not able to check execution
>>> s.str.cat(t, join='right', na_rep='-') 3 dd 0 aa 4 -e 2 -c dtype: object
For more examples, see here <text.concatenate>
.
Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.
Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)
SVG is more flexible but power hungry; and does not scale well to 50 + nodes.
All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them