df1 = pd.DataFrame(columns=["x","y","z"])
df2 = pd.DataFrame({"x":[1],"y":[2]}, index=["foo"])
I'm trying to get this result:
z x y
foo NaN 1 2
I tried
df1.merge(df2,how="outer", on=["x","y"], right_index=True)
which gives the error
MergeError: Can only pass argument "on" OR "left_index" and "right_index", not a combination of both.
However, neither
df1.merge(df2,how="outer", on=["x","y"])
nor
df1.merge(df2,how="outer", left_index=True, right_index=True)
give the desired result...
reindex:df2.reindex(['z', 'x', 'y'], axis=1)df1because it is not always empty. It depends on the user's input.