Wednesday, 18 September 2013

Pyhton pandas: How to combine the data from many data frames into a single data frame with an array as the data values

Pyhton pandas: How to combine the data from many data frames into a single
data frame with an array as the data values

If I have many panda data frames, with the same index structure, I want to
create a data frame with the same index structure but the data values are
np.arrays (actually I want np.matrix.)
Merging seems to do just fine with simple operations df1 + df2 adds
element wise but np.array((df1,df2)) doesn't do at all what I want.
Does pandas have a method of doing this without rebuilding the entire
object element by element?
E.g. if I have
df1 = col1 col2
1 1 2
2 3 4
df2 = col1 col2
1 5 6
2 7 8
and want
df2 = col1 col2
1 [1,5] [2,6]
2 [3,7] [4,8]

No comments:

Post a Comment