gpt4 book ai didi

python - 将 R 代码转换为 Python 的问题

转载 作者:行者123 更新时间:2023-12-01 21:43:10 25 4
gpt4 key购买 nike

from pyensae.languages import r2python

print(r2python(rscript, pep8=True))

我在将 filename.R 转换为 pythonfilename.py 时遇到问题,因为这些库对转换没有用,因为即使我安装了它也会生成错误“找不到模块”该模块使用:

pip install pyensae

最佳答案

以下步骤适用于 Python 版本 Python 3.7.6

  1. 升级你的pip
python -m pip install --upgrade pip
  1. 安装pyensae模块
pip install pyensae
  1. 通过执行下面的 import 检查你的 python 控制台
from pyensae.languages import r2python

如果你面对

ModuleNotFoundError: No module named 'antlr4'

或面向

ModuleNotFoundError: No module named 'builtin'

然后执行下面的命令

pip install antlr4-python3-runtime

经过上述步骤,我可以将R脚本转换成python语言

rscript = """
nb=function(y=1930){
debut=1816
MatDFemale=matrix(D$Female,nrow=111)
colnames(MatDFemale)=(debut+0):198
cly=(y-debut+1):111
deces=diag(MatDFemale[:,cly[cly%in%1:199]])
return(c(B$Female[B$Year==y],deces))}
"""
from pyensae.languages import r2python
print(r2python(rscript, pep8=True))

控制台输出

ANTLR runtime and generated code versions disagree: 4.9.1!=4.8 ANTLRruntime and generated code versions disagree: 4.9.1!=4.8 frompython2r_helper import make_tuple

def nb(y=1930):
debut = 1816
MatDFemale = matrix(D . Female, nrow=111)
colnames(MatDFemale) .set(range((debut + 0), 198))
cly = range((y - debut + 1), 111)
deces = diag(MatDFemale[:, cly[set(cly) & set(range(1, 199))]])
return make_tuple(B . Female[B . Year == y], deces)

关于python - 将 R 代码转换为 Python 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61039549/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com