From 93c40f279f9de2f2f880ee9e717f2318cebbc547 Mon Sep 17 00:00:00 2001 From: phofl Date: Wed, 29 Sep 2021 22:12:31 +0200 Subject: [PATCH 1/2] DOC: Add cross merge to userguide section --- doc/source/user_guide/merging.rst | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/doc/source/user_guide/merging.rst b/doc/source/user_guide/merging.rst index 09b3d3a8c96df..6074b6a02c371 100644 --- a/doc/source/user_guide/merging.rst +++ b/doc/source/user_guide/merging.rst @@ -562,7 +562,7 @@ all standard database join operations between ``DataFrame`` or named ``Series`` (hierarchical), the number of levels must match the number of join keys from the right DataFrame or Series. * ``right_index``: Same usage as ``left_index`` for the right DataFrame or Series -* ``how``: One of ``'left'``, ``'right'``, ``'outer'``, ``'inner'``. Defaults +* ``how``: One of ``'left'``, ``'right'``, ``'outer'``, ``'inner'``, ``'cross'``. Defaults to ``inner``. See below for more detailed description of each method. * ``sort``: Sort the result DataFrame by the join keys in lexicographical order. Defaults to ``True``, setting to ``False`` will improve performance @@ -707,6 +707,7 @@ either the left or right tables, the values in the joined table will be ``right``, ``RIGHT OUTER JOIN``, Use keys from right frame only ``outer``, ``FULL OUTER JOIN``, Use union of keys from both frames ``inner``, ``INNER JOIN``, Use intersection of keys from both frames + ``cross``, ``CROSS JOIN``, Create the karthesian product of rows of both frames .. ipython:: python @@ -751,6 +752,17 @@ either the left or right tables, the values in the joined table will be p.plot([left, right], result, labels=["left", "right"], vertical=False); plt.close("all"); +.. ipython:: python + + result = pd.merge(left, right, how="cross") + +.. ipython:: python + :suppress: + + @savefig merging_merge_cross.png + p.plot([left, right], result, labels=["left", "right"], vertical=False); + plt.close("all"); + You can merge a mult-indexed Series and a DataFrame, if the names of the MultiIndex correspond to the columns from the DataFrame. Transform the Series to a DataFrame using :meth:`Series.reset_index` before merging, From d97684c249faff8bab9d6b57c922667e1dbc2658 Mon Sep 17 00:00:00 2001 From: phofl Date: Thu, 30 Sep 2021 09:27:18 +0200 Subject: [PATCH 2/2] Fix error --- doc/source/user_guide/merging.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/user_guide/merging.rst b/doc/source/user_guide/merging.rst index 6074b6a02c371..cee12c6939b25 100644 --- a/doc/source/user_guide/merging.rst +++ b/doc/source/user_guide/merging.rst @@ -707,7 +707,7 @@ either the left or right tables, the values in the joined table will be ``right``, ``RIGHT OUTER JOIN``, Use keys from right frame only ``outer``, ``FULL OUTER JOIN``, Use union of keys from both frames ``inner``, ``INNER JOIN``, Use intersection of keys from both frames - ``cross``, ``CROSS JOIN``, Create the karthesian product of rows of both frames + ``cross``, ``CROSS JOIN``, Create the cartesian product of rows of both frames .. ipython:: python