import numpy as np
import pandas as pd
A = pd.DataFrame({'key': ['s1', 's2', 's3', 's4'],
'xvalue': [1, 2, 3, 5],
'group':['a' , 'a' , 'b' , 'b']})
B = pd.DataFrame({'key': ['f1', 'f2', 'f3', 'f4'],
'yvalue': [6, 7, 8, 9]})
A
B
left = pd.DataFrame({'a': [1, 2, 3, 5], 'left_val': ['s1', 's2', 's3', 's4']})
left
right = pd.DataFrame({'b': [6, 7, 8, 9], 'left_val': ['f1', 'f2', 'f3', 'f4']})
right
pd.merge_ordered(left, right)
pd.merge_ordered(A, B, fill_method='ffill', left_by='group')