1In [5]: df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6], 'C':[7,8,9]},
2 ...: index=["one", "two", "three"])
3 ...:
4
5In [6]: r_dataframe = pandas2ri.py2ri(df)
6
7In [7]: print(type(r_dataframe))
8<class 'rpy2.robjects.vectors.DataFrame'>
9
10In [8]: print(r_dataframe)
11 A B C
12one 1 4 7
13two 2 5 8
14three 3 6 9
15
1In [1]: from rpy2.robjects import r, pandas2ri
2
3In [2]: pandas2ri.activate()
4
1In [3]: r.data('iris')
2Out[3]:
3R object with classes: ('character',) mapped to:
4<StrVector - Python:0x12a3f3f08 / R:0x7f896c23cf38>
5['iris']
6
7In [4]: r['iris'].head()
8Out[4]:
9 Sepal.Length Sepal.Width Petal.Length Petal.Width Species
101 5.1 3.5 1.4 0.2 setosa
112 4.9 3.0 1.4 0.2 setosa
123 4.7 3.2 1.3 0.2 setosa
134 4.6 3.1 1.5 0.2 setosa
145 5.0 3.6 1.4 0.2 setosa
15