I want to use the R dataset in python

The pandas.rpy module is deprecated and will be removed in a future version. We refer to external packages like rpy2. It seems that it is good to use rpy2.

Enter with pip install rpy2.

ipython


In [1]: from rpy2.robjects import pandas2ri

#If you do this, rpy2.robjects.vectors.DataFrame to pandas.core.frame.Converts to DataFrame
In [2]: pandas2ri.activate()

In [3]: from rpy2.robjects import r

In [10]: r["iris"].head(10)
Out[10]:
    Sepal.Length  Sepal.Width  Petal.Length  Petal.Width Species
1            5.1          3.5           1.4          0.2  setosa
2            4.9          3.0           1.4          0.2  setosa
3            4.7          3.2           1.3          0.2  setosa
4            4.6          3.1           1.5          0.2  setosa
5            5.0          3.6           1.4          0.2  setosa
6            5.4          3.9           1.7          0.4  setosa
7            4.6          3.4           1.4          0.3  setosa
8            5.0          3.4           1.5          0.2  setosa
9            4.4          2.9           1.4          0.2  setosa
10           4.9          3.1           1.5          0.1  setosa

In [11]: type(r["iris"])
Out[11]: pandas.core.frame.DataFrame

In [12]: type(r["Titanic"])
Out[12]: numpy.ndarray

reference

http://pandas.pydata.org/pandas-docs/stable/r_interface.html#updating-your-code-to-use-rpy2-functions

Postscript @ 2016/12/5

rpy2

Installing should be as easy* as
pip install rpy2
(*: except on Windows)

It seems that there is a way to use PypeR because it is ruthless and ruthless, but I feel that it has stopped in 2012, but is it okay?

Recommended Posts

I want to use the R dataset in python
I want to display the progress in Python!
I want to write in Python! (3) Utilize the mock
I want to use Python in the environment of pyenv + pipenv on Windows 10
[Python] I want to use the -h option with argparse
How to use the C library in Python
I want to use MATLAB feval with python
I want to create a window in Python
I want to merge nested dicts in Python
I want to use Temporary Directory with Python2
I want to use ceres solver from python
I want to use the activation function Mish
I want to batch convert the result of "string" .split () in Python
I want to explain the abstract class (ABCmeta) of Python in detail.
I want to use the Django Debug Toolbar in my Ajax application
I want to write in Python! (1) Code format check
I tried to graph the packages installed in Python
I want to embed a variable in a Python string
I want to easily implement a timeout in python
I want to use self in Backpropagation (tf.custom_gradient) (tensorflow)
I want to write in Python! (2) Let's write a test
Even in JavaScript, I want to see Python `range ()`!
I wanted to use the Python library from MATLAB
I want to randomly sample a file in Python
I want to inherit to the back with python dataclass
I want to work with a robot in python.
How to use the model learned in Lobe in Python
I want to do something in Python when I finish
I want to manipulate strings in Kotlin like Python!
[Python] I want to know the variables in the function when an error occurs!
Use PIL in Python to extract only the data you want from Exif
I want to get the file name, line number, and function name in Python 3.4
How to use SQLite in Python
How to use Mysql in python
How to use ChemSpider in Python
How to use PubChem in Python
I wrote the queue in Python
I want to debug with Python
I wrote the stack in Python
I want to use the latest gcc without sudo privileges! !!
I want to initialize if the value is empty (python)
I want to use R functions easily with ipython notebook
maya Python I want to fix the baked animation again.
I want to easily delete columns containing NA in R
How to use the __call__ method in a Python class
I want to do something like sort uniq in Python
I want to use only the normalization process of SudachiPy
I didn't know how to use the [python] for statement
I tried to implement the mail sending function in Python
I want to make the Dictionary type in the List unique
I want to align the significant figures in the Numpy array
I want to make input () a nice complement in python
I didn't want to write the AWS key in the program
I want to use a python data source in Re: Dash to get query results
I just want to find the 95% confidence interval for the difference in population ratios in Python
I want to replace the variables in the python template file and mass-produce it in another file.
I want to pin Spyder to the taskbar
[Introduction to Python] How to use class in Python?
I want to output to the console coolly
I want to use a wildcard that I want to shell with Python remove
I want to know the weather with LINE bot feat.Heroku + Python