Table to table augmentation

I have one table with many rows and columns. One of those columns is username. It is not unique. I have a second table of user details where the username is unique. I would like to add user details from the second table to first table. I can’t identify the correct way to do that. 'join’ing tables does not work.

Suggestions ?

1 Like

Hi @ejaeger.its.jnj.com, welcome to the Datagrok Community!

Is this something you are wanting to achieve?

//name: augmentTable
//language: JavaScript

let T1 = DG.DataFrame.fromCsv(
`username,stars
Ann,1
John,2
Lisa,2
John,5
Anton,3`
);

let T2 = DG.DataFrame.fromCsv(
`username,city
Ann,New York
John,San Francisco
Lisa,Seattle
Anton,Dallas`
);

let T = grok.data.joinTables(
  T1, T2, ['username'], ['username'], ['stars'], ['city'],
  DG.JOIN_TYPE.LEFT, false);
grok.shell.addTableView(T);

You can run this code in https://public.datagrok.ai/js.

It is also possible to achieve the desired result in the Datagrok UI (select “Join type: left” in the dialog):

2 Likes

@dskatov , thanks for answering! I did record a video, but the screenshot you provided explained it perfectly. Let me still add a video though :slight_smile:

2 Likes

I tried the UI but I get the error message that my username in table1 is not unique and so I can not proceed.
image

Most likely, this warning concerns the “All Janssen People (2)” table. Since the uniqueness of the column values in first table is not important for the left join type.

It may be enough for you to swap tables in Tables field selectors.

You are correct. I had duplicates in the second table that I had to fix. A possible UI improvement would be to move the warning for the 2nd table to be aligned with the second column in the dialog.

1 Like

this is a good point, thanks!

Good catch, we’ll definitely make it more intuitive. Also, we’ll add an option to introduce case-insensitive matching for string columns, as this appears to be a common source of confusion.

1 Like

Just in case, here’s how to convert the column to upper case: