0

I have a data frames(df1) with two columns(e.g. A and A_NEW). A is supposed to be a default join key between df1 and another data frame (df2). I want to join df1 and df2 in a way that if there is no match between df1.A and df2.key, then join based on df1.A_NEW and and df2.key. Imagine following scenario: enter image description here

It means value of join attribute could be either in df1.A or df1.A_NEW but our priority is df1.A. If there is no match between df1.A and df2.key, then df1.A_NEW should be checked with df2.key.

I appreciate if you could help me with inner join and left outer join scenarios.

lv10
  • 1,469
  • 7
  • 25
  • 46
user3665906
  • 185
  • 13
  • 1
    Try not to share screenshots! Share an actual data sample and expected output. read: [mcve] or look around at other questions here on SO. – Anton vBR May 02 '18 at 21:02
  • You are trying to do a conditional join/merge. As mentioned in this SO post: https://stackoverflow.com/questions/23508351/how-to-do-a-conditional-join-in-python-pandas?answertab=active#tab-top , there are several ways to achieve this. – lv10 May 02 '18 at 21:14
  • Thanks but My question is totally different. In all of solutions in your suggested doc, join key is the same and there are different conditions. In my case, join key could be either field1 or field2. – user3665906 May 06 '18 at 00:33

0 Answers0