convert_to_r_dataframe module object has no attribute

风流意气都作罢 提交于 2020-01-05 08:15:28

问题


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

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

The first command goes through 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 troubleshoot it. Earlier in the code I have import pandas as pd Could this be the problem?

I am using python 2.7.3, rpy2-2.3.2 and 2.15.3


回答1:


It works for me:

>>> 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]

Different rpy2 version though..



来源:https://stackoverflow.com/questions/15209636/convert-to-r-dataframe-module-object-has-no-attribute

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!