9

I want to join 2 dataframes and I'm using the intructions in the Julia guide: http://dataframesjl.readthedocs.org/en/latest/joins_and_indexing.html?highlight=join

join(a, b, on = :ID, kind = :inner)

Now, how I can join on columns with different names:

  • :ID for a
  • :name_id for b

I tried the following but it doesn't work"

join(a, b, on = [ :ID, :name_id ], kind = :inner)

If not implemented, that would be nice feature

thelatemail
  • 91,185
  • 12
  • 128
  • 188
Guillaume
  • 1,277
  • 2
  • 13
  • 21

2 Answers2

3

The docs on DataFrames.jl provide this example:

innerjoin(a, b, on = [:City => :Location, :Job => :Work])

So for your example:

j = innerjoin(a, b, on = :ID => :name_id)
FeFiFoFu
  • 1,069
  • 1
  • 11
  • 15
2
rename!(b, "name_id", "ID")
j = join(a, b, on = :ID, kind = :inner)
rename!(b, "ID", name_id")

The rename changes b, so here I changed it back. (In the general case if there are renaming conflicts within a dataframe you can pick a unique name for each pair of joined names, rename in each dataframe, join and rename back.)

This method is obviously not elegant. It's what I've found so far.

philipxy
  • 14,867
  • 6
  • 39
  • 83
  • I gather this actually alters the original `b` object? Is there a way to set names on the fly akin to R's `setNames()`, which edits and returns a copy? If not, then I guess this is the way to go. – thelatemail Dec 22 '14 at 23:29