有没有简单的方法在R和Python之间传递数据框?

2024-06-02 21:15:56 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在寻找一种在R和Python之间传递数据帧的方法,而不是编写csv文件。你知道吗

我正在用R编写一个包,我想用Python来处理更繁重的计算。你知道吗

我目前使用的是system2,从这个source

这不是我的程序,但这里是R的基本思想

run_splitstr.R

command ="python“

Note the single + double quotes in the string (needed if paths have spaces)
path2script='"path/to your script/splitstr.py"'

Build up args in a vector
string ="3523462---12413415---4577678---7967956---5456439"
pattern ="---"
args = c(string, pattern)

# Add path to script as first arg
allArgs = c(path2script, args)

output = system2(command, args=allArgs, stdout=TRUE)

print(paste("The Substrings are:\n", output))

这在我的机器上运行得很好,但我必须在Python和R之间将数据帧作为单独的csv文件传递,我担心这将不能被接受,以便它成为一个包。你知道吗

对于Windows系统,还有比这更好的方法吗?或者整个想法都是徒劳的。你知道吗

谢谢!你知道吗


Tags: 文件csvthetopath方法instring