6

I'm trying to import pandas as pd. I get ModuleNotFoundError: No module named 'pandas.rpy'. Why? I use pandas 0.20.1 + python 3.6 x64 + Windows 7 .

Example:

import os
os.environ['R_HOME'] = 'C:\Program Files\R\R-3.4.0'
os.environ['R_USER'] = 'bob'

import rpy2.robjects as robjects
import pandas.rpy.common as com
import pandas as pd

Returns:

Traceback (most recent call last):
  File "C:\doc\GitHub\proj\src\open_rdata.py", line 19, in <module>
    import pandas.rpy.common as com
ModuleNotFoundError: No module named 'pandas.rpy'
Florian
  • 24,425
  • 4
  • 49
  • 80
Franck Dernoncourt
  • 77,520
  • 72
  • 342
  • 501

1 Answers1

8

pandas.rpy module was deprecated and later removed. It does not exist in the version you are currently using.

You can either downgrade your pandas version, or better yet, have a look at the new rpy2 project.

From pandas documentation:

Up to pandas 0.19, a pandas.rpy module existed with functionality to convert between pandas and rpy2 objects. This functionality now lives in the rpy2 project itself. See the updating section of the previous documentation for a guide to port your code from the removed pandas.rpy to rpy2 functions.

You can see the rpy2 documentation here, and panda's reference for it here.

edit: per Analytical Monk's comment, corrected the phrasing to refer rpy2 as a different library, and not a part of pandas

Ori
  • 1,680
  • 21
  • 24
  • 1
    There's no `pandas.rpy2` module. `rpy2` is a separate python library. Documentation for the same is provided here: https://rpy2.readthedocs.io/en/version_2.8.x/ – Analytical Monk Dec 28 '18 at 13:49