The convert_to_r_dataframe module object does not have an attribute

I am new to python and learning pandas. I want to convert the pandas "datframe" data frame to an R-style data frame (to use rpy2 later). There are two lines in my code for this:

import pandas.rpy.common as com  
r_dataframe = com.convert_to_r_dataframe(datframe)

The first command passes, but then I get the following error:

Traceback (most recent call last):
  File "", line 1, in 
    r_dataframe = com.convert_to_r_dataframe (datframe)
AttributeError: 'module' object has no attribute 'convert_to_r_dataframe' "

I am not sure why this is happening and how to fix it. Earlier in the code I have import pandas as pd. Could this be a problem?

I am using python 2.7.3, rpy2-2.3.2 and 2.15.3

+1
1

:

>>> import rpy2
>>> import pandas as pd
>>> import pandas.rpy.common as com
>>> rpy2.__version__
'2.3.1'
>>> pd.__version__
'0.10.0'
>>> datframe = pd.DataFrame({'a' : [1, 2, 3], 'b' : [3, 4, 5]})
>>> r_df = com.convert_to_r_dataframe(datframe)
>>> r_df
<DataFrame - Python:0x105b12710 / R:0x7fa8131d7918>
[IntVector, IntVector]
  a: <class 'rpy2.robjects.vectors.IntVector'>
  <IntVector - Python:0x105b12ab8 / R:0x7fa8131d7838>
[       1,        2,        3]
  b: <class 'rpy2.robjects.vectors.IntVector'>
  <IntVector - Python:0x105b12950 / R:0x7fa8131d7800>
[       3,        4,        5]

rpy2, ..

0

Source: https://habr.com/ru/post/1534066/


All Articles