go-gota / gota

Gota: DataFrames and data wrangling in Go (Golang)
Other
2.98k stars 276 forks source link

Joins columns with different names #122

Open julienrbrt opened 4 years ago

julienrbrt commented 4 years ago

It does not seems to be possible to join dataframe if the key has different name between the two dataframes. The only option would be to make a copy of the dataframe and rename the columns.

It would be interesting if it was supported, with the same behavior as dyplr from the tidyverse:

left_join(table1, table2, by = c("first_name" = "name"))

which could look like in gota like

df1.InnerJoin(df2, "first_name = name")

which (I find) better than

df1.InnerJoin(df2.Copy().Rename("first_name", "name"), "first_name")

This could however give some problems with specific column names.

If anyone else has suggestion on how to make that look better, I'll gladly look for a way to implement it.

kniren commented 4 years ago

This is a good suggestion, I would like to see this in place, although I'm not a fan of using a string and would prefer a typesafe solution. With filters we use:

    dataframe.F{
        Colname:    "A",
        Comparator: series.Eq,
        Comparando: "a",
    },

And I think something similar could be done here, maybe:

    dataframe.MergeBy{
        Left:    "A",
        Right: "Different A",
    },