The best way to import R object into Python?

I know that there is a Python package that imports RData file.

But I was wondering if that is the best option for me.

I have Dataframes in R that I want to use in Python.

I was wondering if I should save this as json or csv and then read with pandas in Python, or I should just save it as RData and use the rpy2 package.

All I need is just turn these R dataframes into Python data frame, so I can manipulate and combine with other results I calculated in Python...


You can use feather .

It's a data format for data frames (created by @Wes McKinney and @hadley ) to make data sharing between R and python easy (and some other languages too).

In R :

library(feather)
file_path <- "foo.feather"  
data_frame <- read_feather(file_path)    
write_feather(data_frame, file_path)

In python :

import feather
file_path = 'foo.feather'
data_frame = feather.read_dataframe(file_path)
feather.write_dataframe(data_frame, file_path)

PS.: Podcast on feather where authors discuss it's application, pros/cons and future.

链接地址: http://www.djcxy.com/p/6540.html

上一篇: 那里有什么样的兼容性?

下一篇: 将R对象导入Python的最佳方法是什么?