@@ -33,27 +33,24 @@ See also the documentation of the `rpy2 <http://rpy2.bitbucket.org/>`__ project:
33
33
34
34
In the remainder of this page, a few examples of explicit conversion is given. The pandas conversion of rpy2 needs first to be activated:
35
35
36
- .. ipython ::
36
+ .. ipython :: python
37
37
:verbatim:
38
38
39
- In [1]: from rpy2.robjects import pandas2ri
40
- ...: pandas2ri.activate()
39
+ >> > from rpy2.robjects import pandas2ri
40
+ >> > pandas2ri.activate()
41
41
42
42
Transferring R data sets into Python
43
43
------------------------------------
44
44
45
45
Once the pandas conversion is activated (``pandas2ri.activate() ``), many conversions
46
46
of R to pandas objects will be done automatically. For example, to obtain the 'iris' dataset as a pandas DataFrame:
47
47
48
- .. ipython ::
48
+ .. ipython :: python
49
49
:verbatim:
50
50
51
- In [2]: from rpy2.robjects import r
52
-
53
- In [3]: r.data('iris')
54
-
55
- In [4]: r['iris'].head()
56
- Out[4]:
51
+ >> > from rpy2.robjects import r
52
+ >> > r.data(' iris' )
53
+ >> > r[' iris' ].head()
57
54
Sepal.Length Sepal.Width Petal.Length Petal.Width Species
58
55
0 5.1 3.5 1.4 0.2 setosa
59
56
1 4.9 3.0 1.4 0.2 setosa
@@ -71,19 +68,15 @@ Converting DataFrames into R objects
71
68
The ``pandas2ri.py2ri `` function support the reverse operation to convert
72
69
DataFrames into the equivalent R object (that is, **data.frame **):
73
70
74
- .. ipython ::
71
+ .. ipython :: python
75
72
:verbatim:
76
73
77
- In [5]: df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6], 'C': [7, 8, 9]},
78
- ...: index=["one", "two", "three"])
79
-
80
- In [6]: r_dataframe = pandas2ri.py2ri(df)
81
-
82
- In [7]: print(type(r_dataframe))
83
- Out[7]: <class 'rpy2.robjects.vectors.DataFrame'>
84
-
85
- In [8]: print(r_dataframe)
86
- Out[8]:
74
+ >> > df = pd.DataFrame({' A' : [1 , 2 , 3 ], ' B' : [4 , 5 , 6 ], ' C' : [7 , 8 , 9 ]},
75
+ ... index = [" one" , " two" , " three" ])
76
+ >> > r_dataframe = pandas2ri.py2ri(df)
77
+ >> > print (type (r_dataframe))
78
+ < class ' rpy2.robjects.vectors.DataFrame' >
79
+ >> > print (r_dataframe)
87
80
A B C
88
81
one 1 4 7
89
82
two 2 5 8
0 commit comments