【2】文件读写-6-1-python与R的dataframe的交互--rpy2
Dataframe作为一个二维的数据结构,实现python与R的交互,能够更好的通过python来调用R的脚本哦
1.python 形成dataframe
from pandas import DataFrame
aa = DataFrame()
xs = [1,2,3,4,5,6]
....
aa['loc_x'] = xs
aa['loc_y']= ys
aa['pheno_type']= phenos
aa['id_shapes']= ids_shape
2.python与R的dataframe的交互–rpy2
方法一:
import rpy2.robjects as robjects
## get a reference to the R function
write_csv = robjects.r('write.csv')
## save
write_csv(df_R,'filename.csv')
#x=c(6,1,4,5,5,1)
#y=c(1,5,4,2,6,6)
#z=c(1,1,1,1,2,2)
#xy =c ("XX","YY","XY","XX","XY","YY")
#aa
方法二
from rpy2.robjects import pandas2ri
pandas2ri.activate()
from rpy2.robjects.packages import importr
base = importr('base')
# call an R function on a Pandas DataFrame
base.summary(my_pandas_dataframe)
参考资料
这里是一个广告位,,感兴趣的都可以发邮件聊聊:tiehan@sina.cn
个人公众号,比较懒,很少更新,可以在上面提问题,如果回复不及时,可发邮件给我: tiehan@sina.cn
个人公众号,比较懒,很少更新,可以在上面提问题,如果回复不及时,可发邮件给我: tiehan@sina.cn