What is the best way to merge two deedle frames that have overlapping rows? I would like to keep the rows unique, though. As far as I understand, merge() does not allow overlapping rows.
Asked
Active
Viewed 1,032 times
4
-
What is the row key? And what do you want the row key to be after the merging? (In other words, does it make sense to have multiple values for a single key?) – Tomas Petricek Oct 15 '15 at 21:17
-
so if I have two frames, both have columns "id" and "name", df1 has 2 rows id = 1, name = John, and id = 2, name = Mike, and df2 has 2 rows two with id =1, name = John, and id = 3, name = Bob. I would like to combine two frames and the new frame to have 3 unique rows, with John, Mike, and Bob . Sorry about the structure of the post. I dont know how to make a table here – alexshchep Oct 15 '15 at 21:35
1 Answers
5
If the row keys are just ordinal numbers and have no meaning, then you probably just want to replace the keys with new ordinal index. Sadly, there is no built-in version of merge that would do this for you, but you can write something like this:
var df1Ord = df1.IndexRowsWith(Enumerable.Range(0, df1.RowCount));
var df2Ord = df2.IndexRowsWith(Enumerable.Range(df1.RowCount, df2.RowCount));
var res = df1Ord.Merge(df2Ord);
Here, we just replace the row keys with new non-overlapping keys and then merge them.
I think having a method for this would be nice, so feel free to open an issue on Deedle GitHub page and send a pull request!

Tomas Petricek
- 240,744
- 19
- 378
- 553
-
That works, but now I have repeating rows in the new frame. How should I go about deleting redundant rows based on one column ("id")? – alexshchep Oct 16 '15 at 02:43
-
2Thank you! I searched so long for this. Coming from Python Pandas I feel Deedle is a bit of a crutch, really wondering why such basic features are missing? – CodeMonkey Jun 20 '16 at 15:49