简体   繁体   English

为什么我收到“模块'rpy2.robjects.conversion'没有属性'py2rpy'”错误?

[英]Why am I getting “module 'rpy2.robjects.conversion' has no attribute 'py2rpy'” error?

I'm trying to convert a pandas dataframe into an R dataframe using the guide here .我正在尝试使用此处的指南将 pandas dataframe 转换为 R Z6A8064B5DF479450550053。 The code I have so far is:我到目前为止的代码是:

import pandas as pd
import rpy2.robjects as ro
from rpy2.robjects import pandas2ri

from rpy2.robjects.conversion import localconverter

pd_df = pd.DataFrame({'int_values': [1, 2, 3],
                      'str_values': ['abc', 'def', 'ghi']})

with localconverter(ro.default_converter + pandas2ri.converter):
  r_from_pd_df = ro.conversion.py2rpy(pd_df)

However, this is giving me the following error:但是,这给了我以下错误:

Traceback (most recent call last):
  File <my_file_ref>, line 13, in <module>
    r_from_pd_df = ro.conversion.py2rpy(pd_df)
AttributeError: module 'rpy2.robjects.conversion' has no attribute 'py2rpy'

I have found this relevant question where the OP refers to function names being changed however doesn't explain what the changes are.我发现了这个相关问题,其中 OP 指的是 function 名称正在更改,但没有解释更改是什么。 I've tried looking at the module but I'm not quite advanced enough to be able to make sense of it.我试过看这个模块,但我还不够先进,无法理解它。

The accepted answer refers to checking versions which I've done and I'm definitely using rpy2 v3.3.3 which is the same as the guide I'm following.接受的答案是指检查我已经完成的版本,并且我肯定使用的是 rpy2 v3.3.3,这与我正在遵循的指南相同。

Has anyone encountered this error and found a solution?有没有人遇到这个错误并找到了解决方案?

The section of the rpy2 documentation you are pointing out is built by running the code example.您指出的 rpy2 文档部分是通过运行代码示例构建的。 This is means that the example did work with the corresponding version of rpy2.这意味着该示例确实适用于相应版本的 rpy2。

I am not sure you are using that version of rpy2 at runtime?我不确定您在运行时使用的是该版本的 rpy2 吗? For example, add print(rpy2.__version__) to check that this is the case.例如,添加print(rpy2.__version__)以检查是否是这种情况。

For what is worth, the latest release in the rpy2 3.3.x series is 3.3.6 and there is probably no good reason to stay with 3.3.3.值得一提的是,rpy2 3.3.x 系列的最新版本是 3.3.6,可能没有充分的理由继续使用 3.3.3。 Otherwise rpy2 3.4.0 was just released;否则 rpy2 3.4.0 刚刚发布; if using R 4.0 or greater, or the latest release of the R packages dplyr or ggplot2 together with their rpy2 wrapper, I would recommend to use that release. if using R 4.0 or greater, or the latest release of the R packages dplyr or ggplot2 together with their rpy2 wrapper, I would recommend to use that release.

[PS: I just tried your example with rpy2-3.4.0 and it runs without error] [PS:我刚刚用 rpy2-3.4.0 试过你的例子,它运行没有错误]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Django 中的 Rpy2 错误 - 转换 'py2rpy' 未为类型 ' 的对象定义<class 'str'></class> - Rpy2 Error in Django - Conversion 'py2rpy' not defined for objects of type '<class 'str'> Python 脚本中的 RPY2 错误! (未为类型为“的对象定义转换‘py2rpy’<class 'pandas.core.frame.dataframe'> ')</class> - RPY2 error in Python script! (Conversion 'py2rpy' not defined for objects of type '<class 'pandas.core.frame.DataFrame'>') Python 错误 - NotImplementedError: 转换 'py2rpy' 没有为类型的对象定义<class 'ipywidgets.widgets.widget_string.text'> '</class> - Python Error - NotImplementedError: Conversion 'py2rpy' not defined for objects of type '<class 'ipywidgets.widgets.widget_string.Text'>' 导入rpy2.robjects会出错 - Import rpy2.robjects gives error 获取分段错误从rpy2导入robject时出现核心转储错误 - Getting Segmentation fault Core dumped error while importing robjects from rpy2 rpy2.robjects.r和rpy2.robjects.globalenv之间的区别 - Difference between `rpy2.robjects.r` and `rpy2.robjects.globalenv` 为什么我在添加“as”时得到模块没有属性错误 - Why Am I getting Module has no attribute error when adding "as" 为什么rpy2.robjects.lib.grid.viewport()返回ListVector,但不返回Viewport? - Why rpy2.robjects.lib.grid.viewport() return ListVector,but not viewport? 熊猫和rpy2:为什么ezANOVA通过robjects.r而不是robjects.packages.importr起作用? - pandas and rpy2: Why does ezANOVA work via robjects.r but not robjects.packages.importr? NotImplementedError: 转换 'rpy2py' 没有为类型 ' 的对象定义<class 'rpy2.rinterface.sexpclosure'> ' 只有在我运行代码两次之后</class> - NotImplementedError: Conversion 'rpy2py' not defined for objects of type '<class 'rpy2.rinterface.SexpClosure'>' only after I run the code twice
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM