这实际上只是一个连接。
In [14]: arrays = [['bar', 'bar', 'baz', 'baz'],['one', 'two', 'one', 'two']]
In [15]: tuples = list(zip(*arrays))
In [16]: index1 = pd.MultiIndex.from_tuples(tuples, names=['first', 'second'])
In [17]: arrays = [['foo', 'foo', 'qux', 'qux'],['one', 'two', 'one', 'two']]
In [18]: tuples = list(zip(*arrays))
In [19]: index2 = pd.MultiIndex.from_tuples(tuples, names=['first', 'second'])
In [21]: df1 = pd.DataFrame(np.random.randn(4,4), columns=index1)
In [23]: df2 = pd.DataFrame(np.random.randn(4,4), columns=index2)
In [25]: pd.concat([df1, df2], axis=1)
Out[25]:
first bar baz foo qux \
second one two one two one two one
0 0.192217 -1.392671 1.229953 0.558334 -0.908125 0.934284 -1.240591
1 0.816492 -0.157933 0.058365 -1.115411 -0.488677 0.204860 -0.268372
2 -0.160077 -1.825912 0.615397 0.570057 -0.699260 -0.552970 0.056875
3 1.308078 0.018694 1.047227 1.047585 0.172404 0.861871 0.569599
first
second two
0 -2.234618
1 -1.604534
2 0.151859
3 0.522803