I have following DataFrames:
stores = [['AA', 12, 'Red'], ['BB', 13, 'Red'], ['BB', 14, 'Red'], ['BB', 15, 'Red']]
visits = [['BB', 13, 'Green'], ['BB', 14, 'Blue']]
stores_df = pd.DataFrame(data=stores, columns=['retailer', 'store', 'color'])
stores_df.set_index(['retailer', 'store'], inplace=True)
visits_df = pd.DataFrame(data=visits, columns=['retailer', 'store', 'color'])
visits_df.set_index(['retailer', 'store'], inplace=True)
color
retailer store
BB 13 Green
14 Blue
color
retailer store
AA 12 Red
BB 13 Red
14 Red
15 Red
我该如何合并它们以获得以下结果:
color
retailer store
AA 12 Red
BB 13 Green
14 Blue
15 Red
update
会就地更改,没有返回值。这些都是非常有用的功能。+1 - piRSquared