https://github.com/saurfang/reticulate.df
Reticulate DataFrame Conversion via Apache Arrow
https://github.com/saurfang/reticulate.df
Last synced: 2 months ago
JSON representation
Reticulate DataFrame Conversion via Apache Arrow
- Host: GitHub
- URL: https://github.com/saurfang/reticulate.df
- Owner: saurfang
- License: other
- Created: 2017-07-16T08:24:03.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2017-07-16T10:43:19.000Z (almost 8 years ago)
- Last Synced: 2025-03-27T07:35:56.154Z (3 months ago)
- Language: R
- Homepage:
- Size: 8.79 KB
- Stars: 9
- Watchers: 2
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.Rmd
- License: LICENSE
Awesome Lists containing this project
README
---
output: github_document
---```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "README-"
)
library(dplyr)
```# reticulate.df
[](https://travis-ci.org/saurfang/reticulate.df)
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:
```{r gh-installation, eval = FALSE}
# install.packages("devtools")
devtools::install_github("saurfang/reticulate.df")
```## Example
From Python to R
```{r example}
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
```{r}
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_
```