You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The parameter ``others`` can also be two-dimensional. In this case, the number or rows must match the lengths of the calling ``Series`` (or ``Index``).
251
256
252
257
.. ipython:: python
253
258
254
-
u = pd.Series(['b', 'd', 'e', 'c'], index=[1, 3, 4, 2])
255
-
# without alignment
259
+
d = pd.concat([t, s], axis=1)
260
+
s
261
+
d
262
+
s.str.cat(d, na_rep='-')
263
+
264
+
Concatenating a Series and an indexed object into a Series, with alignment
For concatenation with a ``Series`` or ``DataFrame``, it is possible to align the indexes before concatenation by setting
270
+
the ``join``-keyword.
271
+
272
+
.. ipython:: python
273
+
274
+
u = pd.Series(['b', 'd', 'a', 'c'], index=[1, 3, 0, 2])
275
+
s
276
+
u
256
277
s.str.cat(u)
257
-
# with separate alignment
258
-
v, w = s.align(u)
259
-
v.str.cat(w, na_rep='-')
278
+
s.str.cat(u, join='left')
279
+
280
+
.. warning::
281
+
282
+
If the ``join`` keyword is not passed, the method :meth:`~Series.str.cat` will currently fall back to the behavior before version 0.23.0 (i.e. no alignment),
283
+
but a ``FutureWarning`` will be raised if any of the involved indexes differ, since this default will change to ``join='left'`` in a future version.
284
+
285
+
The usual options are available for ``join`` (one of ``'left', 'outer', 'inner', 'right'``).
286
+
In particular, alignment also means that the different lengths do not need to coincide anymore.
Copy file name to clipboardExpand all lines: doc/source/whatsnew/v0.23.0.txt
+18
Original file line number
Diff line number
Diff line change
@@ -308,6 +308,24 @@ The :func:`DataFrame.assign` now accepts dependent keyword arguments for python
308
308
309
309
df.assign(A=df.A+1, C= lambda df: df.A* -1)
310
310
311
+
.. _whatsnew_0230.enhancements.str_cat_align:
312
+
313
+
``Series.str.cat`` has gained the ``join`` kwarg
314
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
315
+
316
+
Previously, :meth:`Series.str.cat` did not -- in contrast to most of ``pandas`` -- align :class:`Series` on their index before concatenation (see :issue:`18657`).
317
+
The method has now gained a keyword ``join`` to control the manner of alignment, see examples below and in :ref:`here <text.concatenate>`.
318
+
319
+
In v.0.23 `join` will default to None (meaning no alignment), but this default will change to ``'left'`` in a future version of pandas.
320
+
321
+
.. ipython:: python
322
+
323
+
s = pd.Series(['a', 'b', 'c', 'd'])
324
+
t = pd.Series(['b', 'd', 'e', 'c'], index=[1, 3, 4, 2])
325
+
s.str.cat(t)
326
+
s.str.cat(t, join='left', na_rep='-')
327
+
328
+
Furthermore, meth:`Series.str.cat` now works for ``CategoricalIndex`` as well (previously raised a ``ValueError``; see :issue:`20842`).
0 commit comments