Is there a way to perform an operation between two dataframes?
For example, suppose we have a couple of dataframes:
df1 = pd.DataFrame({'a': randn(5), 'b': randn(5)})
df2 = pd.DataFrame({'c': randn(5), 'd': randn(5)})
df1
a b
0 -0.287740 -0.255126
1 -0.356745 0.632524
2 -0.379608 -0.876348
3 -0.596401 0.937805
4 0.969356 0.421352
df2
c d
0 -0.505406 -0.921449
1 0.508703 0.844641
2 0.300125 -0.942838
3 0.711138 -0.364033
4 -0.370174 -1.284353
And I'd like to perform an operation (maybe, a correlation) between the rows of df1 and df2. Using this example, I want something like this in a new dataframe:
corr([-0.287740 -0.255126],[-0.505406 -0.921449])
corr([-0.356745 0.632524],[0.508703 0.844641])
...
corr([0.969356 0.421352],[-0.370174 -1.284353])
Although, using the respective columns would also be possible by simply transposing df1 and df2.
I think this should be possible, although the original problem was related to numpy arrays, which would be stated in the following way:
Suppose a couple of arrays i and j:
i = np.random.random((5,2))
j = np.random.random((5,2))
i
array([[ 0.88005044, 0.60633474],
[ 0.1183816 , 0.61705454],
[ 0.24259704, 0.8490759 ],
[ 0.66581795, 0.31805491],
[ 0.89337085, 0.21212527]])
j
array([[ 0.52745975, 0.07748147],
[ 0.36152729, 0.74438265],
[ 0.48207699, 0.28462384],
[ 0.08623375, 0.55043213],
[ 0.26371755, 0.23409753]])
How can I correlate the first array of i [ 0.88005044, 0.60633474]
with the first array of j [ 0.52745975, 0.07748147]
?