gpt4 book ai didi

python - rpy2 : Korean characters are not working on rpy2

转载 作者:太空狗 更新时间:2023-10-30 03:00:44 25 4
gpt4 key购买 nike

python 代码:

import rpy2.robjects as robjects

rCommand='''gender <- c("남자", "남자", "남자", "여자", "여자", "여자", "여자", "여자")
age <- c(23, 25, 27, 29, 31, 33, 35, 37)
outdf <- data.frame(gender, age)
'''
robjects.r(rCommand)
resultDf_r=robjects.globalenv["outdf"]

print type(resultDf_r)

韩文字符使 python.exe 被杀死。

在 R 命令终端中,上面的“rCommand”运行良好。

我找不到任何解决方案。

如有任何帮助,我们将不胜感激。

我的环境:window 7 x64,python 2.7.8 x64,rpy2 2.5.4,R 3.1.2

最佳答案

在撰写本文时,遗憾的是没有对 Windows 的 rpy2 的官方支持。您提供的代码片段在 Linux 上运行良好。

您的选择可能是:

  • 在 Linux VM(或容器 - MS 已宣布支持 Docker)中运行您的代码

  • 提交 rpy2 的补丁

  • 在 bitbucket 页面上为 rpy2 提交错误报告,希望有人将其转化为补丁

编辑:评论表明帮助 Python 2.7 编码可能会有所帮助(没有 promise - 一切都在 Linux 上工作,所以这可能是特定于 Windows 的)。一个字符串可以明确指定为 unicode 格式(注意 ''' 之前的前缀 u):

rCommand=u'''
gender <- c("남자", "남자", "남자", "여자", "여자", "여자", "여자", "여자")
age <- c(23, 25, 27, 29, 31, 33, 35, 37)
outdf <- data.frame(gender, age)
'''
robjects.r(rCommand)

关于python - rpy2 : Korean characters are not working on rpy2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28247851/

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