Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Join examples #2728

Merged
merged 17 commits into from
Dec 1, 2020
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -55,3 +55,4 @@ src/datatable/_build_info.py

# vscode settings
.vscode/settings.json
.vscode/c_cpp_properties.json
4 changes: 4 additions & 0 deletions docs/api/dt/join.rst
Expand Up @@ -3,3 +3,7 @@
:src: src/core/expr/py_join.cc ojoin::pyobj::m__init__
:doc: src/core/expr/py_join.cc doc_join
:tests: tests/test-join.py




54 changes: 53 additions & 1 deletion src/core/expr/py_join.cc
Expand Up @@ -62,7 +62,59 @@ except: ValueError

See Also
--------
- :ref:`Tutorial on joins <join tutorial>`
- `Tutorial on joins <../../start/quick-start.html#join>`_

Examples
--------
st-pasha marked this conversation as resolved.
Show resolved Hide resolved

Examples
--------

.. code-block:: python

df1 = dt.Frame(""" date X1 X2
01-01-2020 H 10
01-02-2020 H 30
01-03-2020 Y 15
01-04-2020 Y 20""")

df2 = dt.Frame("""X1 X3
H 5
Y 10""")


First, create a key on the right frame (``df2``). Note that the join key(``X1``) has unique values and has the same name in the left frame(``df1``)::

df2.key = "X1"

Join is now possible::

df1[:, :, join(df2)]

.. dtframe::
:names: date,X1,X2,X3
:types: str32,str32,int8,int8
:shape: 4, 4

0,01-01-2020,H,10,5
1,01-02-2020,H,30,5
2,01-03-2020,Y,15,10
3,01-04-2020,Y,20,10

You can access the values in the right frame in an expression, using the secondary namespace object `g <https://datatable.readthedocs.io/en/latest/api/dt/g.html>`__::
samukweku marked this conversation as resolved.
Show resolved Hide resolved

df1[:, update(X2=f.X2 * g.X3), join(df2)]
df1

.. dtframe::
:names: date,X1,X2
:types: str32,str32,int8
:shape: 4, 3

0,01-01-2020,H,50
1,01-02-2020,H,150
2,01-03-2020,Y,150
3,01-04-2020,Y,200
)";

static PKArgs args___init__(
Expand Down