I have data of the form:
frame1 = pd.DataFrame({'supplier1_match0': ['x'], 'id': [1]})
frame2 = pd.DataFrame({'supplier1_match0': ['2x'], 'id': [2]})
and wish to left join multiple frames to a frame like this:
base_frame = pd.DataFrame({'id':[1,2,3]})
I merge on the id and get:
merged = base_frame.merge(frame1, how='left', left_on='id', right_on='id')
merged = merged.merge(frame2, how='left', left_on='id', right_on='id')
id supplier1_match0_x supplier1_match0_y
0 1 x NaN
1 2 NaN 2x
2 3 NaN NaN
The column is duplicated and a 'y' is appended. Here is what I need:
id, supplier1_match0, ...
1, x
2, 2x
3, NaN
Is there a simple way to achieve this? There is a similar question (Nested dictionary to multiindex dataframe where dictionary keys are column labels) but the data has a different shape. Note that I have multiple suppliers and that they have varying numbers of matches, so I can't assume the data will have a "rectangular" shape. Thanks in advance.