我知道有一个导入RData文件的Python包。
但是我想知道那是否对我来说是最好的选择。
我在R中有要在Python中使用的数据框。
我想知道是否应该将其另存为json或csv,然后在Python中使用pandas读取,或者我应该将其另存为RData并使用rpy2包。
我所需要的只是将这些R数据框转换为Python数据框,以便我可以操纵并与我在Python中计算出的其他结果结合起来...
您可以使用feather
。
这是一种数据帧的数据格式(由@Wes McKinney和@hadley创建),以使数据共享变得容易R
且python
容易(以及其他一些语言)。
在R
:
library(feather)
file_path <- "foo.feather"
data_frame <- read_feather(file_path)
write_feather(data_frame, file_path)
在python
:
import feather
file_path = 'foo.feather'
data_frame = feather.read_dataframe(file_path)
feather.write_dataframe(data_frame, file_path)
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句