I would use the Panel structure for this:
In [11]: p = pd.Panel({'df1': df1, 'df2': df2}) In [12]: p['df1'] Out[12]: col1 col2 1 1 2 2 3 4
And you can apply to the main axis:
In [13]: p.apply(np.sum, axis='major')
Note: for each pair (df, col) you use a numpy array:
In [21]: def f(x): print(repr(x)) return 1 In [22]: p.apply(f, 'major') array([1, 3]) array([2, 4]) array([5, 7]) array([6, 8]) Out[22]: df1 df2 col1 1 1 col2 1 1
You can choose another numpy / linalg function (or create your own).
Update: this is actually not quite what you want, you need to use the axis of the elements:
In [31]: p.apply(f, 'items') array([1, 5]) array([2, 6]) array([3, 7]) array([4, 8]) Out[31]: col1 col2 1 1 1 2 1 1
source share