0

I'm very new in Python. I have two dataframes like this:

df1 is like:

df1 = pd.DataFrame({'aa': ['x3er', 'x5tu'],'code1': ['marhua', 'marsogot'],'code2':['andigan','mauliate']})

and df2 is like:

  df2 = pd.DataFrame({'ad': ['x3er','x3er','x3er','x5tu','x5tu','x5tu','x5tu','x5tu'],'ae': [5,6,7,8,9,10,11,12],'af':[7,1,4,8,9,10,19,14]})

Note: I want to join these two dataframes with common keyaa and ad then copy the differences so then they are have same number of rows. The desired result with new key ap is like this:

df3 = pd.DataFrame({'ap': ['x3er','x3er','x3er','x5tu','x5tu','x5tu','x5tu','x5tu'],
                'code1': ['marhua','marhua','marhua','marsogot','marsogot','marsogot',
                         'marsogot','marsogot'],
                'code2':['andigan','andigan','andigan','mauliate',
                         'mauliate','mauliate','mauliate','mauliate'],
               'ae': [5,6,7,8,9,10,11,12],'af':[7,1,4,8,9,10,19,14]})

Thanks in advance for your helping! Please help me to solve this

0 Answers0