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
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
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
29
Other Decks in Technology
See All in Technology
Why is RC4 still being used?
tamaiyutaro
0
250
IaC コードを資産へ:AWS CDK 社内ライブラリと横断展開 / aws-summit-japan-2026
gotok365
10
1.7k
製造現場での生成AIの活用、およびエージェントAIの実装のあり方、AVEVAの取り組み
iotcomjpadmin
0
200
Kotlin 開発のツラミを爆破した話! / Explode the difficulty of Kotlin dev!
eller86
0
120
PostgreSQL 19 新機能概要 OSC Hokkaido 2026
nori_shinoda
0
260
AIで政治は変わるのか? — 中高生と考えたAI時代の民主主義(東海高校サタデープログラム)
eitarosuda
0
230
CVE-2026-20833_脆弱性対応とAES 化について
jukishiya
0
300
AWS Summit 2026で見えたSIerにとっての Amazon Quickの位置づけ
maf_0521
0
130
5分でわかるDuckDB Quack
chanyou0311
4
280
『AIに負けない』より『AIと遊ぶ』」〜ワクワクが最強のテスト・QA学習戦略_公開用
odan611
1
220
40代で“やっとエンジニアになれた”――閉じた学びを開き、空の青さを知る / 20260628 Naoki Takahashi
shift_evolve
PRO
4
1.4k
【FinOps】データドリブンな意思決定を目指して
z63d
3
540
Featured
See All Featured
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
254
22k
Jess Joyce - The Pitfalls of Following Frameworks
techseoconnect
PRO
1
170
Building Experiences: Design Systems, User Experience, and Full Site Editing
marktimemedia
0
540
Bioeconomy Workshop: Dr. Julius Ecuru, Opportunities for a Bioeconomy in West Africa
akademiya2063
PRO
1
160
DevOps and Value Stream Thinking: Enabling flow, efficiency and business value
helenjbeal
1
250
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
17k
Lightning Talk: Beautiful Slides for Beginners
inesmontani
PRO
2
590
Believing is Seeing
oripsolob
1
160
Neural Spatial Audio Processing for Sound Field Analysis and Control
skoyamalab
0
350
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.7k
SEO Brein meetup: CTRL+C is not how to scale international SEO
lindahogenes
1
2.7k
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
420
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