diff --git a/ci/deps/travis-36-doc.yaml b/ci/deps/travis-36-doc.yaml index f79fcb11c179f..fb54c784d6fac 100644 --- a/ci/deps/travis-36-doc.yaml +++ b/ci/deps/travis-36-doc.yaml @@ -2,7 +2,6 @@ name: pandas channels: - defaults - conda-forge - - r dependencies: - beautifulsoup4 - bottleneck @@ -31,14 +30,11 @@ dependencies: - python-snappy - python=3.6* - pytz - - r - - rpy2 - scipy - seaborn - sphinx - sqlalchemy - statsmodels - - tzlocal - xarray - xlrd - xlsxwriter diff --git a/doc/source/r_interface.rst b/doc/source/r_interface.rst index 88634d7f75c63..d0b2601668069 100644 --- a/doc/source/r_interface.rst +++ b/doc/source/r_interface.rst @@ -33,10 +33,10 @@ See also the documentation of the `rpy2 `__ project: In the remainder of this page, a few examples of explicit conversion is given. The pandas conversion of rpy2 needs first to be activated: -.. ipython:: python +.. code-block:: python - from rpy2.robjects import r, pandas2ri - pandas2ri.activate() + >>> from rpy2.robjects import pandas2ri # doctest: +SKIP + >>> pandas2ri.activate() # doctest: +SKIP Transferring R data sets into Python ------------------------------------ @@ -44,10 +44,17 @@ Transferring R data sets into Python Once the pandas conversion is activated (``pandas2ri.activate()``), many conversions of R to pandas objects will be done automatically. For example, to obtain the 'iris' dataset as a pandas DataFrame: -.. ipython:: python +.. code-block:: python - r.data('iris') - r['iris'].head() + >>> from rpy2.robjects import r # doctest: +SKIP + >>> r.data('iris') # doctest: +SKIP + >>> r['iris'].head() # doctest: +SKIP + Sepal.Length Sepal.Width Petal.Length Petal.Width Species + 0 5.1 3.5 1.4 0.2 setosa + 1 4.9 3.0 1.4 0.2 setosa + 2 4.7 3.2 1.3 0.2 setosa + 3 4.6 3.1 1.5 0.2 setosa + 4 5.0 3.6 1.4 0.2 setosa If the pandas conversion was not activated, the above could also be accomplished by explicitly converting it with the ``pandas2ri.ri2py`` function @@ -59,13 +66,19 @@ Converting DataFrames into R objects The ``pandas2ri.py2ri`` function support the reverse operation to convert DataFrames into the equivalent R object (that is, **data.frame**): -.. ipython:: python +.. code-block:: python + + >>> df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6], 'C': [7, 8, 9]}, + ... index=["one", "two", "three"]) # doctest: +SKIP + >>> r_dataframe = pandas2ri.py2ri(df) # doctest: +SKIP + >>> print(type(r_dataframe)) # doctest: +SKIP + + >>> print(r_dataframe) # doctest: +SKIP + A B C + one 1 4 7 + two 2 5 8 + three 3 6 9 - df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6], 'C':[7,8,9]}, - index=["one", "two", "three"]) - r_dataframe = pandas2ri.py2ri(df) - print(type(r_dataframe)) - print(r_dataframe) The DataFrame's index is stored as the ``rownames`` attribute of the data.frame instance.