0

I am trying to merge two dataframe that are multi-index, while preserving the highest level index. The problem is merging on axis=1 results in the below two columns. Merging/joining on axis=0 drops any value in the 0_y column that has the same sub-index as an entry in )_x. An example below is (226,0), where the value 1510123295301 gets dropped if I merge/join on axis=0.

Is there any way to merge two multi-index dataframes into a single column, preserving the primary index (e.g. 226), but expanding to include non-duplicates in the right-hand column (e.g. 226(0-6))?

enter image description here

enter image description here

4
  • Are you looking for df2.combine_first(df)? Commented Sep 25, 2017 at 18:28
  • I tried that, but it drops anything in the second dataframe with the same index as the first. For example, the (226,0) 1510123295301 is dropped. Commented Sep 25, 2017 at 18:37
  • Then would you do df.combine_first(df2)? You could just reverse the dataframes. Commented Sep 25, 2017 at 18:39
  • Then it drops 014113734066. If an entry in both columns has both a primary and secondary index in common, one of the entries will get dropped. I need the subindex to expand to merge entries from both columns. Commented Sep 25, 2017 at 18:45

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.