Generate some data in Python:
In [1]:
import pandas as pd
import numpy as np
In [2]:
# Generate matrix
my_df = np.random.random((3, 3))
my_df
Out[2]:
Enable use of R:
In [3]:
%load_ext rpy2.ipython
Use R to manipulate the Python data:
In [4]:
%%R -i my_df
# "-i" is to load Python variable into R
my_df
In [5]:
%%R -o my_rowsum
# "-o" is export variable from R to Python
# Sum over rows
(my_rowsum <- apply(my_df, 1, sum))
Back to Python:
In [6]:
my_rowsum
Out[6]: