如何在索引和列上合并两个数据框

Here's the problem: I know how to merge two DataFrames on indexes or on columns, but I am not able to merge them on a both indexes and columns.

I have two DataFrames and I want to merge them on indexes (which are dates) and on column id. I created some sample data to better explain my problem.

from datetime import date
import numpy as np
import pandas as pd

np.random.seed(200)
ids = ["A", "B"]
dates = [date(2020, 1, 31), date(2020, 2, 28)]
a = {"id": ids * len(dates), "w": [.5, .5] * len(dates)}
b = {"id": ids * len(dates), "x": np.random.random(len(ids) * len(dates))}

a = pd.DataFrame(a, index=dates * len(dates))
b = pd.DataFrame(b, index=dates * len(dates))

所需的输出:

           id    w         x
2020-01-31  A  0.5  0.947632
2020-02-28  B  0.5  0.226547
2020-01-31  A  0.5  0.594420
2020-02-28  B  0.5  0.428309

Please note that I am searching for a general solution, where a and b do not necessarily contains the same indexes or elements in id.