Skip to content

Commit 742f496

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 2fdf1e2 commit 742f496

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

doc/source/merging.rst

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

306328
Concatenating with mixed ndims

doc/source/whatsnew/v0.23.0.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,7 @@ Documentation Changes
658658
Rewrote some sentences for greater clarity, added more dynamic references
659659
to functions, methods and classes.
660660
(:issue:`18941`, :issue:`18948`, :issue:`18973`, :issue:`19017`)
661+
- Added a reference to :func:`DataFrame.assign` in the concatenate section of the merging documentation (:issue:`18665`)
661662
-
662663

663664
.. _whatsnew_0230.bug_fixes:

0 commit comments

Comments
 (0)