Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Use R from Python
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
airspace_nobo
July 27, 2019
Technology
370
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Use R from Python
airspace_nobo
July 27, 2019
More Decks by airspace_nobo
See All by airspace_nobo
Try using dbtplyr
airspace_nobo
0
34
Other Decks in Technology
See All in Technology
Bet AI Day 2026丨バクラク Autopilot、業務システムの再設計
layerx
PRO
1
810
Master Dataグループ紹介資料
sansan33
PRO
1
4.9k
AI駆動開発をチームに根付かせる - 「1行も書かない」チームがHarnessを育てた1年 -
kenichirokimura
6
3.6k
Guerilla InnerSource in enterprises, during the AI hype
onenashev
PRO
0
130
Does an AI Watermark Survive Translation?
machinetranslation
0
520
指示待ちから変化に応じるClaude Codeへ!~環境からAgentへの帰り道を作る~
gotalab555
9
1.8k
AIで開発は速くなったのに、なぜ現場は楽にならないのか 〜あなたの組織のボトルネックを突き止めるワークショップ〜
jacopen
1
190
多摩川(.dev)ランニング入門 / Tamagawa.dev#3
fujiwara3
3
190
Self Healing Rollouts: Automating Production Fixes with Agentic AI
kdubois
0
130
いかに伝えるか 〜新卒エンジニアの教育のための、ライトノベル活用の一例
ikedon
1
160
When Does a Local Qwen Start to Break
morshoto
0
110
Eight Engineering Unit 紹介資料
sansan33
PRO
3
8.3k
Featured
See All Featured
The Illustrated Children's Guide to Kubernetes
chrisshort
51
53k
The Curse of the Amulet
leimatthew05
2
14k
Building a A Zero-Code AI SEO Workflow
portentint
PRO
0
700
Measuring & Analyzing Core Web Vitals
bluesmoon
9
990
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
3k
How to audit for AI Accessibility on your Front & Back End
davetheseo
0
520
Getting science done with accelerated Python computing platforms
jacobtomlinson
2
460
Heart Work Chapter 1 - Part 1
lfama
PRO
8
36k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
49
10k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
254
22k
Digital Projects Gone Horribly Wrong (And the UX Pros Who Still Save the Day) - Dean Schuster
uxyall
1
2.6k
ラッコキーワード サービス紹介資料
rakko
1
4.7M
Transcript
6TF3GSPN1ZUIPO 5PLZP3 !BJSTQBDF@OPCP
ࣗݾհ w ໊લখ௶ୖਓ,PUTVCP5BLVUP w 5XJUUFS!BJSTQBDF@OPCP w ݱࡏम࢜ ༛༧िؒ w
ະདྷσʔλαΠΤϯςΟετ w ݚڀγϦϯυϦΧϧλΠϜγϦʔζ w ༻3 1ZUIPO ࡱӨऀ!LVSDLZ@Z
ࢲͱ3ͱ1ZUIPO w 3σʔλϋϯυϦϯά HHQMPU ౷ܭղੳؔ࿈ ٸ͍ͰΔ࣌ w 1ZUIPOػցֶश LFSBT εΫϥον͢Δ࣌
͓ۚՔ͙࣌ ͓ޓ͍ͷྑ͍ͱ͜ΖΛ͏·͘Ҿ͖ग़͍ͨ͠
QZQFSࣄ࢝Ί w QJQͰΠϯετʔϧ w SQZQFS3 Λ࣮ߦ͠ SΠϯελϯεʹ SίʔυΛ จࣈྻͱͯ͠༩͑Δ w
݁ՌΛදࣔ͢Δ࣌ʹ QSJOUΛ͏ r = pyper.R() r("a <- 5") print(r("a")) # ݁Ռ # try({a}) # [1] 5 r("b <- 10") print(r("a + b")) # ݁Ռ # try({a + b}) # [1] 15 pip install pyper
w Sͱಉ༷ʹ ಡΈࠐΜͰ͍ͳ͍ QBDLBHFͷؔ͑ͳ͍ w ؔΛಡΈࠐΊ ύΠϓԋࢉࢠ ͑Δʂ r =
pyper.R() print(r("glimpse(iris)")) # not find function "glimpse" r = pyper.R() r("library(tidyverse)") print(r("glimpse(iris)")) # try({glimpse(iris)}) print(r("iris %>% glimpse")) # try({iris %>% glimpse}) QZQFSؔಡΈࠐΈ
QZQFS QZUIPOS w SQZQFS3 VTF@QBOEBTb5SVF` Ͱ QBOEBT%BUB'SBNF͕͑Δ w SBTTJHOؔͰ
EG QZUIPO Λ Q@EG S ʹׂΓͯΔ n = 300 x = np.random.poisson(10, n) y = np.random.normal(0, 5, n) # dataFrame df = pd.DataFrame({"X":x, "Y":y}) r = pyper.R(use_pandas='True') r.assign("p_df", df) print(r("summary(p_df)"))
QZQFS SQZUIPO w SHFUؔ SͷσʔλΛQZUIPOଆͰ ༻Ͱ͖ΔΑ͏ʹ͢Δ w σʔλͷܕҎԼʹͳΔ ϕΫτϧOVNQZBSSBZ
σʔλϑϨʔϜQBOEBT%BUB'SBNF r = pyper.R() r("rx <- rexp(300,1)") r("rdf <- data.frame(x = 1:200, y = rnorm(200))") px = r.get(“rx") pdf = r.get("rdf") plt.hist(px, bins=20) plt.ylabel("freq") plt.show()
QZQFS SQZUIPO w σʔλϑϨʔϜܕΛQZUIPOʹ࣋ͬͯ͘Δͱ ΧϥϜ໊ʹεϖʔε͕ೖΔͷ Ͱ औΓআ͘ඞཁ͋Δʂʂ print(pdf.columns) pdf.columns
= pdf.columns.str.replace(' ', '') print(pdf.columns) Index(['x', 'y'], dtype='object')
Ϣʔβࣗ࡞ؔ w σʔλͷߦྻΛදࣔ͢Δؔ TIBQF@EBUB Λఆٛͨ͠εΫϦϓτϑΝ ΠϧΛ SͰಡΈࠐΉΑ͏ʹQZUIPOΛ௨ͯ͡ಡΈࠐΊΔ shape_data <- function(data){
sprintf("σʔλ%dߦ, %dྻͰ͢!!",NROW(data), NCOL(data)) } r = pyper.R(use_pandas='True') r("source('~/Desktop/TokyoR/script/function.R', echo=FALSE)") print(r("shape_data(iris)"))
Ϣʔβࣗ࡞ؔ w ͪΖΜQZUIPOଆ͔Β༩͑ͨσʔλʹରͯࣗ͠࡞ؔΛద༻Մೳ σʔλ͕গ͠ҟͳΔͷͰ ྻʹͳΔ w ΠϯελϯεΛॳظԽ͠ͳ͚Ε ؔอ࣋͞ΕΔʂ from
sklearn.datasets import load_iris iris = load_iris() iris = pd.DataFrame(data=iris.data, columns=iris.feature_names) r.assign("p_iris", iris) print(r("shape_data(p_iris)"))
ศརͳ͍ํΛߟ͑Δ w SͰ͜Μͳؔ࡞ͬͯʜ w QZUIPOͰ͜Μͳؔ࡞Εʜ library(tidyverse); library(skimr) view_data <- function(data){
print("use skim function"); skim(data) %>% kable print("use glimpse function"); glimpse(data) } def view_data(data): r = pyper.R(use_pandas='True') r("source('~/Desktop/TokyoR/script/function.R', echo=FALSE)") r.assign("p_data", data) print(r(“view_data(p_data)”)) view_data(iris)
ศརͳ͍ํΛߟ͑Δ w ͜Μͳ݁Ռ͕ಘΒΕΔ
ศརͳ͍ํΛߟ͑Δ w ͬͺΓSͰHHQMPUΛॻ͖͍ͨ࣌ ͦͦTUBU@DPOUPVS͍͍ͨ࣌ UIFNF@NJOBNBM ͡Όͳ͍ͱݏͩʂͱ͍͏࣌ w QZUIPOͰΞϧΰϦζϜΛεΫϥονͯ͠ ࣮ߦ݁ՌΛHHQMPUͰඒ͘͠ඳ͖ ͍ͨ࣌
େ͖ͳ w దͳσʔλϑϨʔϜΛ࡞ ͢ΔؔΛ࡞Δ w 3ͰͷEBUBGSBNF࡞࣌ؒ 1ZUIPOͷσʔλҠߦ࣌ؒ w LBHHMFͱ͔Ͱ
લॲཧ3Ͱॻ ͍ͯ σʔλͦͷ··ࣸͯ͠ ػցֶशʹҠߦ͢ΔΈ͍ͨͳ ͜ͱ͕Ͱ͖ͳ͍ fun <- function(len){ df1 <- tibble(aaa = 1:len, bbb = 10000:10000+len, ccc = 1000000:1000000+len, ddd = rbinom(len,1,0.5), eee = rnorm(len, 0, 100000), fff = rlnorm(len, 0, 100), ggg = stri_rand_strings(n=len, length=10), hhh = seq(as.Date("2018-03-07"), by="day", length.out=len)) return(df1) } MFO 3 1ZUIPO TFD TFD TFD TFD TFD ແཧ
·ͱΊ w ԿΒ͔ͷཧ༝͕͋ͬͯ QZUIPOSΘͳ͍ͱ͍͚ͳ͍࣌ SͰ࡞ͨ͠ ؔΛ͑Δͷ࣌ؒతʹ อकతʹศར w ࣗͰ͏ʹͳͦ͞͏͕ͩ
ਓʹ࡞ͨ͠ίʔυΛ͢ͳͲͷ࣌ ҙ͕ඞཁ w ձࣾͰ1ZUIPO͔͑͠ͳ͍ਓ͕ͨͪ ͬͦ͜Γ͑Δ w SFUJDVMBUFQBDLBHFͷํ͕ศར ݸਓͷײ
3PS1ZUIPO 8IZOPU#PUI &OKPZ