pandas: 如何通过与另一个面板合并来沿短轴延伸

pandas: how to extend along minor-axis by merging with another Panel

我有两个面板都有相同的列('Open'、'Close'、'Volume' 等),major_axis 是日期时间,minor_axis 是股票代码。

我想将两者连接/合并在一起,这样列就不会改变,但我现在拥有沿短轴的所有股票代码。

请注意,不能保证 major_axis 中的日期时间完全相同,我需要一个外部联接(或等效的)。

正如我正在做的文档所建议的那样:

 p1.join(p2, how='outer')

但出现错误:

ValueError: columns overlap but no suffix specified: Index([u'Open', u'High', u'Low', u'Close', u'Volume', u'Adj Close'], dtype='object')

如果我指定了后缀,我最终会得到 12 列。

有什么建议吗?

pd.concataxis=2

结合使用

示例

tidx = pd.date_range('2015-03-31', periods=3, freq='M')

list1 = ['IBM', 'APPL']
list2 = ['CVX', 'BHP']

items = ['Open', 'Close', 'High', 'Low']

p1 = pd.Panel(np.random.rand(4, 3, 2), items, tidx, list1)
p2 = pd.Panel(np.random.rand(4, 3, 2), items, tidx, list2)

# <- This is the answer ->
pd.concat([p1, p2], axis=2).to_frame()