Skip to content

Commit e0613b7

Browse files
committed
Review of @datapythonista
Signed-off-by: Fabian Haase <[email protected]>
1 parent 62c6c68 commit e0613b7

File tree

1 file changed

+14
-21
lines changed

1 file changed

+14
-21
lines changed

doc/source/r_interface.rst

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -33,27 +33,24 @@ See also the documentation of the `rpy2 <http://rpy2.bitbucket.org/>`__ project:
3333

3434
In the remainder of this page, a few examples of explicit conversion is given. The pandas conversion of rpy2 needs first to be activated:
3535

36-
.. ipython::
36+
.. ipython:: python
3737
:verbatim:
3838
39-
In [1]: from rpy2.robjects import pandas2ri
40-
...: pandas2ri.activate()
39+
>>> from rpy2.robjects import pandas2ri
40+
>>> pandas2ri.activate()
4141
4242
Transferring R data sets into Python
4343
------------------------------------
4444

4545
Once the pandas conversion is activated (``pandas2ri.activate()``), many conversions
4646
of R to pandas objects will be done automatically. For example, to obtain the 'iris' dataset as a pandas DataFrame:
4747

48-
.. ipython::
48+
.. ipython:: python
4949
:verbatim:
5050
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()
5754
Sepal.Length Sepal.Width Petal.Length Petal.Width Species
5855
0 5.1 3.5 1.4 0.2 setosa
5956
1 4.9 3.0 1.4 0.2 setosa
@@ -71,19 +68,15 @@ Converting DataFrames into R objects
7168
The ``pandas2ri.py2ri`` function support the reverse operation to convert
7269
DataFrames into the equivalent R object (that is, **data.frame**):
7370

74-
.. ipython::
71+
.. ipython:: python
7572
:verbatim:
7673
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)
8780
A B C
8881
one 1 4 7
8982
two 2 5 8

0 commit comments

Comments
 (0)