knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "README-" ) library(dplyr)
The goal of reticulate.df is to experiment conversion between R data.frame and Python pandas DataFrame in reticulate.
You can install reticulate.df from github with:
# install.packages("devtools") devtools::install_github("saurfang/reticulate.df")
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_
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.