Skip to content

Commit 0ed539f

Browse files
committed
DOC: added a reference to DataFrame assign in concatenate section of merging
Because of various stack overflow answers we are directed to the merging page where a link to DataFrame.assign would be better. Adding the reference here will make people's code better. At least it would have for me.
1 parent fdba133 commit 0ed539f

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

doc/source/merging.rst

+22
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,28 @@ This is also a valid argument to ``DataFrame.append``:
303303
labels=['df1', 'df4'], vertical=True);
304304
plt.close('all');
305305
306+
.. _merging.assign:
307+
308+
Concatenating using ``assign``
309+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
310+
311+
You can concatenate one Series to a DataFrame using the DataFrame method
312+
:meth:`~pandas.DataFrame.assign`. This will add a column to the DataFrame using
313+
the Series' data. New columns can be potentially derived from existing columns.
314+
315+
.. ipython:: python
316+
317+
s1 = pd.Series(['X0', 'X1', 'X2', 'X3'])
318+
result = df1.assign(X = s1)
319+
320+
.. ipython:: python
321+
:suppress:
322+
323+
@savefig merging_assign.png
324+
p.plot([df1, s1], result,
325+
labels=['df1', 's1'], vertical=False);
326+
plt.close('all');
327+
306328
.. _merging.mixed_ndims:
307329

308330
Concatenating with mixed ndims

doc/source/whatsnew/v0.21.1.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ Performance Improvements
4848
Documentation Changes
4949
~~~~~~~~~~~~~~~~~~~~~
5050

51-
-
51+
- Added a reference to :func:`DataFrame.assign` in the concatenate section of the merging documentation (:issue:`18665`)
5252
-
5353
-
5454

0 commit comments

Comments
 (0)