Skip to content

Commit b797bfd

Browse files
author
Nick Eubank
committed
Added to docs
1 parent cf8412f commit b797bfd

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

doc/source/merging.rst

+7-1
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ standard database join operations between DataFrame objects:
356356

357357
merge(left, right, how='left', on=None, left_on=None, right_on=None,
358358
left_index=False, right_index=False, sort=True,
359-
suffixes=('_x', '_y'), copy=True)
359+
suffixes=('_x', '_y'), copy=True, indicator=False)
360360

361361
Here's a description of what each argument is for:
362362

@@ -387,6 +387,12 @@ Here's a description of what each argument is for:
387387
cases but may improve performance / memory usage. The cases where copying
388388
can be avoided are somewhat pathological but this option is provided
389389
nonetheless.
390+
- ``indicator``: Add a column to the output DataFrame called ``_merge``
391+
with information on the source of each row. ``_merge`` is Categorical-type
392+
and takes on a value of ``left_only`` for observations whose merge key
393+
only appears in ``'left'`` DataFrame, ``right_only`` for observations whose
394+
merge key only appears in ``'right'`` DataFrame, and ``both`` if the
395+
observation's merge key is found in both.
390396

391397
The return type will be the same as ``left``. If ``left`` is a ``DataFrame``
392398
and ``right`` is a subclass of DataFrame, the return type will still be

doc/source/whatsnew/v0.16.1.txt

+9
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,15 @@ Enhancements
7171

7272
- ``DataFrame`` and ``Series`` now have ``_constructor_expanddim`` property as overridable constructor for one higher dimensionality data. This should be used only when it is really needed, see :ref:`here <ref-subclassing-pandas>`
7373

74+
- ``merge`` now accepts the argument ``indicator``. If ``True``, adds a column to output DataFrame called ``_merge`` with information on the source of each row. ``_merge`` is Categorical-type and takes on a value of ``left_only`` for observations whose merge key only appears in ``'left'`` DataFrame, ``right_only`` for observations whose merge key only appears in ``'right'`` DataFrame, and ``both`` if the observation's merge key is found in both. (:issue:`7412` and :issue:`8790`.)
75+
76+
.. ipython:: python
77+
78+
df1 = pd.DataFrame({'col1':[0,1], 'col_left':['a','b']})
79+
df2 = pd.DataFrame({'col1':[1,2,2],'col_right':[2,2,2]})
80+
pd.merge(df1, df2, on='col1', how='outer', indicator=True)
81+
82+
7483
.. _whatsnew_0161.enhancements.categoricalindex:
7584

7685
CategoricalIndex

0 commit comments

Comments
 (0)