knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "README-"
)
library(dplyr)

reticulate.df

Travis-CI Build Status

The goal of reticulate.df is to experiment conversion between R data.frame and Python pandas DataFrame in reticulate.

Installation

You can install reticulate.df from github with:

# install.packages("devtools")
devtools::install_github("saurfang/reticulate.df")

Example

From Python to R

library(reticulate.df)

library(reticulate)
pd <- import("pandas")
np <- import("numpy")


df <- pd$DataFrame(
  list(
    'A' = 1.,
    'B' = pd$Timestamp('20130102'),
    'C' = pd$Series(1, index = seq(4), dtype = 'float32'),
    'D' = np$array(rep(3L, 4), dtype='int32'),
    'E' = pd$Categorical(c("test","train","test","train")),
    'F' = 'foo'
  )
)
class(df)

as.data.frame(df)

From R to Python

py_longley <- as_pandas(longley)

# http://scikit-learn.org/stable/tutorial/statistical_inference/supervised_learning.html#linear-regression
sklearn <- import("sklearn")
regr <- sklearn$linear_model$LinearRegression()
regr$fit(as_pandas(select(longley, -Employed)), py_longley$Employed)
regr$coef_


saurfang/reticulate.df documentation built on May 20, 2019, 7:58 a.m.